Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,449 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Dynamically calling objects from arguments? #115446
03/06/07 05:10
03/06/07 05:10
Joined: Jul 2004
Posts: 59
T
ToddWorld Offline OP
Junior Member
ToddWorld  Offline OP
Junior Member
T

Joined: Jul 2004
Posts: 59
Is it possible in c-script to pass an object name in an argument so you can dynamically reference an object in a function?

example: Let's say I have 2 panels "message_panel" and "warning_panel". And I want to create a function called showPanel() to display...fadeup...whatever a specific panel. Either the message_panel OR the warning_panel in our example.

I'd love to pass the panel name as an argument, let's say showPanel("message_panel");

...and then have the function change the alpha of the panel to fade it up or down. Sort of like:

function showPanel(whichPanel) {
whichPanel.alpha = 50;
}

Of course, this tanks in c-script . Hopefully there's a way to do this...without a bunch of if/then statements inside the showPanel function to account for every possible panel.

Thanks,
Todd

Re: Dynamically calling objects from arguments? [Re: ToddWorld] #115447
03/06/07 05:45
03/06/07 05:45
Joined: Jul 2006
Posts: 503
Australia
A
adoado Offline

User
adoado  Offline

User
A

Joined: Jul 2006
Posts: 503
Australia
You could try passing the Panel as a pointer? Then you can reference it and use the panel you passed..

Hope it helped!
Adoado


Visit our development blog: http://yellloh.com
Re: Dynamically calling objects from arguments? [Re: ToddWorld] #115448
03/06/07 17:15
03/06/07 17:15
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
It is very uncommon to pass string representations as arguments to access objects. Use the pointer method instead and you can access all objects like you have asked for.

Cheers
Christian

Re: Dynamically calling objects from arguments? [Re: HeelX] #115449
03/06/07 22:21
03/06/07 22:21
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline
Serious User
Lion_Ts  Offline
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
Todd, i think, you made your panels in usual way (panel bla_bla_bla{...}). Try to use pan_create at once (see the manual) and you will understand what Heelx says to you.

Re: Dynamically calling objects from arguments? [Re: Lion_Ts] #115450
03/07/07 18:44
03/07/07 18:44
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
Quote:

Is it possible in c-script to pass an object name in an argument so you can dynamically reference an object in a function?



Todd has his own world.
For rare instances, where I actually want get/set element by name behavior, I use a dll plugin.

Code:

panel* pnl0_;
function showPanel(whichPanel) {
// whichPanel parameter might be considered a var or long at this point
// whichPanel.alpha = 50;
// do sort of cast to (panel*)
pnl0_ = whichPanel;
pnl0_.alpha = 50;
}

//...
showPanel(message_panel);
showPanel(warning_panel);
//...



Re: Dynamically calling objects from arguments? [Re: testDummy] #115451
03/09/07 04:41
03/09/07 04:41
Joined: Jul 2004
Posts: 59
T
ToddWorld Offline OP
Junior Member
ToddWorld  Offline OP
Junior Member
T

Joined: Jul 2004
Posts: 59
Thanks again for the suggestions, I'll see if I can try them out.

Now, preparing to get flamed here, but...passing object names like my example is pretty common in Action Script 2.0. But then again, since AS 2 doesn't have pointers...they may have something to do with it.

Did I mention I'm mainly a design guy...but anyhow, my programming background goes way back, but I haven't spent any time with C or C++. Basic...like 1.0 back in '78, Logo (pointless), Pascal, Lingo (Director, and pointless), PERL, javascript and Action Script 1 and 2.

So, bring on the flames...but I do genuinely appreciate the advice.

Thanks,
Todd

p.s. and yes, I do tend to live in my own happy world...my site is www.toddworld.com

Re: Dynamically calling objects from arguments? [Re: ToddWorld] #115452
03/09/07 04:50
03/09/07 04:50
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
"A5 2" ?...

You have to use pointers to panels (and everything else), not the name's of their defined name...


xXxGuitar511
- Programmer
Re: Dynamically calling objects from arguments? [Re: xXxGuitar511] #115453
03/09/07 06:17
03/09/07 06:17
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
Quote:

Now, preparing to get flamed here, but...passing object names like my example is pretty common in Action Script 2.0. But then again, since AS 2 doesn't have pointers...they may have something to do with it.



Quote:

So, bring on the flames...but I do genuinely appreciate the advice.



Quoted ToddWorld ignitable.
I can't determine why you should be flamed for that specifically, and not just for suggesting that you should be flamed, but in the meantime, if you feel you actually deserve to be flamed, perhaps, because you have strong masochistic tendencies, you can start offending and/or insulting yourself in this very thread, right now (no need to pause for effect), but keep in mind, at this time, as a 'pseudo-professional', assuming that I have redefined the term of course, I can not officially recommend that you start flaming yourself.

Wait...if you really, really, like PERL, maybe I can find a match...

Last edited by testDummy; 03/09/07 06:21.
Re: Dynamically calling objects from arguments? [Re: testDummy] #115454
03/09/07 13:21
03/09/07 13:21
Joined: Jul 2004
Posts: 59
T
ToddWorld Offline OP
Junior Member
ToddWorld  Offline OP
Junior Member
T

Joined: Jul 2004
Posts: 59
...well...there was this one time, in band camp.

But seriously, your example looks like it should straighten things out. I was just trying to make a point that even though I'm new to c-script I have had a little experience with programming. Most "hard core" programmers I know are very...opinionated about the langauge they're currently using. As a result I get a nice set of 'eye rolls' if I mention several years of Action Script experience.

It looks like you're not of that mindset. Which is great.

My hope is, even though I'm asking a number of noob questions that things will click relativly quickly, and so far with help from the 3DGS community and other tutorials and examples online, that's pretty much been the case.

I just figured there'd be come virtual eye-rolling going on. But a brothers got to learn somehow. I'll post screens of what I'm working on pretty soon. It's just a small side-scroller/platformer.

Thanks,
Todd

p.s. now I'm just curious as to what you edited...

Re: Dynamically calling objects from arguments? [Re: ToddWorld] #115455
03/11/07 20:26
03/11/07 20:26
Joined: Jul 2004
Posts: 59
T
ToddWorld Offline OP
Junior Member
ToddWorld  Offline OP
Junior Member
T

Joined: Jul 2004
Posts: 59
I think I've set up all my panel declarations correctly, but passing an argument to a function called by an event brought up another problem.

I've got a 'showMessage(whichWindow)' function that I'd like to be able to call for various messages in the game. Each with custom graphics etc. Some of these messages are shown when the player 'reads' a nearby sign so in the action of the sign I have

my.event = showMessage(warningMessage);

The problem is...since I now have included parentheses the function runs automatically as soon as the level runs.

Is there a way to stop this from autorunning....and WHY aren't functions called in a consistant way....i.e. all of them showMessage(), whether there's an arguement or not.

Thanks,
Todd


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1