Forum Topic: Passing variables to functions

(319 views • 8 replies)

This topic is 1 page long.

<< < > >>
None

DifferentName

Reply To Post Reply & Quote

Posted at: 3/16/06 04:38 AM

DifferentName LIGHT LEVEL 16

Sign-Up: 10/08/03

Posts: 279

Does anyone know how to pass variables to functions? it works when i pass a value to a function, like a number or something, but i cant find how to pass a variable that may be true or may be false, to the function.


None

LeechmasterB

Reply To Post Reply & Quote

Posted at: 3/16/06 04:49 AM

LeechmasterB EVIL LEVEL 16

Sign-Up: 04/01/05

Posts: 543

[code]
function passBoolean(theBoolean:Boolean):Void {
trace("Boolean Passed: "+theBoolean);
}

passBoolean(true);

passBoolean(false);
[/code]

Put that in the first frame... it should give you the idea :).


None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 3/16/06 05:07 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 9,716

myVar = 10;
myF ("hello", 3, myVar);

Passes "hello", 3 and 10 to the function.

haXe AliceML Box2dLite Learn AS
#ngprogramming at irc.freenode.net
OVER NINE THOUSAAAAND!!!


None

DifferentName

Reply To Post Reply & Quote

Posted at: 3/16/06 05:11 AM

DifferentName LIGHT LEVEL 16

Sign-Up: 10/08/03

Posts: 279

i've got flash mx, so i think that's why my flash doesn't understand :void and :Boolean. so i just got rid of those and that works... but here's my problem...

i already know how to do
passBoolean(true);

My question is when i have code that makes a variable either true or false, and then in a function something like

passVariable (booleanVariable);

Can flash do that?


None

LeechmasterB

Reply To Post Reply & Quote

Posted at: 3/16/06 05:17 AM

LeechmasterB EVIL LEVEL 16

Sign-Up: 04/01/05

Posts: 543

Yes thats the point, you can pass a variable or a value it will do the same... :)


None

DifferentName

Reply To Post Reply & Quote

Posted at: 3/16/06 06:19 AM

DifferentName LIGHT LEVEL 16

Sign-Up: 10/08/03

Posts: 279

ok... i guess i didn't do enough testing, so thanks for pointing out that it works.

i found out what my code is doing. what i was doing was using a function to spawn enemies, and trying to make them check a variable on every turn. (a different variable for different enemies, which is why i needed to pass it to the function). But what the code is actually doing, is just passing the result of that variable at the time of the enemies creation, and then it checks that same result every turn, rather than checking the new result of the variable each turn. I guess there's no way to do what i thought it would do, so i'll have to reorder my code. thanks for the help.


None

Inglor

Reply To Post Reply & Quote

Posted at: 3/16/06 06:58 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,957

yes, you can do stuff other than call by value in flash, you just pass the parent moveiclip, or the variable name


None

liaaaam

Reply To Post Reply & Quote

Posted at: 3/16/06 12:29 PM

liaaaam NEUTRAL LEVEL 21

Sign-Up: 12/11/04

Posts: 12,766

At 3/16/06 04:49 AM, LeechmasterB wrote: [code]
[/code]

DOES IT SAY BBCODE IS ON? NOOOOOooooOOO.

And yes, Flash MX doesn't have strict data typing.


None

LeechmasterB

Reply To Post Reply & Quote

Posted at: 3/16/06 02:19 PM

LeechmasterB EVIL LEVEL 16

Sign-Up: 04/01/05

Posts: 543

At 3/16/06 12:29 PM, -liam- wrote:
At 3/16/06 04:49 AM, LeechmasterB wrote: [code]
[/code]
DOES IT SAY BBCODE IS ON? NOOOOOooooOOO.

And yes, Flash MX doesn't have strict data typing.

Do you think i did not know that? OOOoooHHHooooOOoHHhh..


All times are Eastern Standard Time (GMT -5) | Current Time: 01:07 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!