Object fade in/out shortcut - passing parameters by reference [SOLVED]

Started by TerranRich, Mon 22/06/2009 23:47:09

Previous topic - Next topic

TerranRich

Hi all,

So I was thinking of creating a shortcut to fading in/out objects, like so:

Code: ags

function ObjectFade (object oObject, bool bFadeIn, int iWaitVal = 1)
{
    int iTrans = oObject.Transparency;
    // etc.
}


However, (1) does AGS support passing parameters by reference yet? and (2) if so, how would I specify that? Or is that already the default action?

I've been out of the AGS loop for quite some time, and so I've forgotten quite a bit. (I used to be a mod on this forum, and now I know less than most newbies :( .)
Status: Trying to come up with some ideas...

GuyAwesome

I'm obviously being dense, but what're you asking/trying to do?
Does 'passing parameters by reference' mean allowing skippable, optional parameters with default values (like eBlock is the default for BlockingStyle in Object.Animate, or 1 would be the default for iWaitVal in your code)? You can do that by setting them in the script header when you import the function. I think there was a trick to allow you to have optional parameters on local functions, but I have no idea how... (If that's not what it means, sorry, I'll have to leave it for someone who knows programming better than me to answer :))

Also, have you seen the FadingThingsNonBlocking module? It has a lot of shortcut options for, well, fading things (Objects, Characters, GUIs) in and out - might do what you want, or at least give you a starting point. Not sure how current the code is, though.
EDIT2:
Thinking about it, I guess you're after making a function that'll change an Object's transparency over time, with bFadeIn specifying fade in or fade out, and iWaitVal being the delay... Pretty obvious after all, I suppose :). If you want non-blocking fades, that module may well be what you're after. If you want blocking fades, not so much.

EDIT:
While not totally necessary, you might want to use extender functions, something like
Code: ags

function Fade (this Object*, bool bFadeIn, int iWaitVal)
{
    int iTrans = this.Transparency;
    // etc. Just use 'this' in place of the 'oObject' parameter
}


Then instead of ObjectFade(oGhost, true, 3); as in your code, you would use oGhost.Fade(true, 3);. As I said not totally essential, but to my mind a little neater looking.

TerranRich

GuyAwesome: That extender function is exactly what I could use. Also, the asterisk (*) after the "Object" parameter is what I was talking about... by passing the object as a reference instead of a value, you can affect what happens to that object outside of the function.

Thanks!!
Status: Trying to come up with some ideas...

SMF spam blocked by CleanTalk