• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Variables in Children Functions?

Status
Not open for further replies.
Level 12
Joined
Apr 27, 2008
Messages
1,228
Here is what I am wondering :D
I have this situation:
JASS:
function ab takes group g integer b returns nothing
//some irrelevant code
endfunction
function something takes nothing returns nothing
local group w = CreateGroup()
local integer a = 0
call ab(w,a)
set w=null
endfunction

If I destroy the group g in ab, will this destroy w in something?
So generally my question is how are parameter variables handled :D
To go even further: if I use "set b=2" in ab(yes that is possible) will this set the value of a in something to 2?
P.s. The second thing is kinda easy to test, but I am going to bed, so if anyone knows, please say, but do not trouble yourself by testing it for me.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Well, as GhostWolf said (with my words xO) when you call a function with parameters, the values inserted in the called code are getting local. So you have to destroy both of the unit groups in your example.

Second, if you call the function with the parameter (w,a) it simply means that local b will be given the value of a. If you set b to something else afterwards, no it wont affect a at all.

Maybe I wrote alittle cake on cake but weh never mind.

/regards
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
The thing is, that I used a group in some function.
JASS:
function lightn takes group g returns nothing
call DestroyGroup(g)
call DoNothing()
endfunction
function Trig_Storm_Caller_Actions takes nothing returns nothing
local group g=CreateGroup()
call lightn(g)
call DestroyGroup(g)
set g=null
endfunction
I destroyed that group in the original function after I called the child one.
In the child function I destroyed the group again.
And a debug message appeared and said that there is a double double free of group in the main function(which is expected as when the child function is called it is executed, than the main function continues).
If I remove either of the call DestroyGroup(g) lines, then the message does not appear. (yes, I added the the call DoNothing() just so that there would be something in the child function when I remove the other line)
Now what do you make of that ?
P.s. About my second question, the answer is just no(after a very fast test).
P.P.s. Maybe I am just walking on the road to finding the H2I bug ;)
As when real, boolean, integer and string are passed the actual value is passed.
But when handles are passed, their address is passed.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
And a debug message appeared and said that there is a double double free of group in the main function

I guess Im tired, but what did you mean xO?

Edit, I saw what you meant, I didnt know that message was showing at all

Edit2: That is indeed weird. I tested to Destroy it only in the child function, and it worked. Hm now I must mixture some myself
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
I have already understood this(I mean how HADNLES are passed as arguments to another function) - by their index/address or whatever you like to call them.
Variables of type handle(all of them) are just a pointer to the actual handle.
So that leads to another question why we null pointers as they are integers :D
 
Status
Not open for further replies.
Top