• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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