Jump to content
Sign in to follow this  
JacobJ

Refering to a local variable?

Recommended Posts

I was wondering how a unit created by script gets refered to, if you use _local names. Ill give an example:

_car = "jeep" createVehicle (getpos location);

If I have another script that I want to use to move this jeep, how do I refer to it? Is the name of the jeep _car or what is the name of the jeep? Do I have to change the local variable _car to a global variable like car?

I know this seems basic, but I really need to understand this, if I want to get these script problems of mine solved.

/Jacob

Share this post


Link to post
Share on other sites

You can either pass the local reference to the script directly:

[color=#3E3E3E]_car = "jeep" createVehicle (getpos location);
[/color]
0 = [[color=#3E3E3E]_car] execVM "movecar.sqf";[/color]

Or if your move script will not run until later you could save the reference into an array to pull out later:

[color=#3E3E3E]_car = "jeep" createVehicle (getpos location);
[/color]
mylistofcars = [[color=#3E3E3E]_car];[/color]

then later:

_car = mylistofcars select 0;

_car setPos _newpos

Share this post


Link to post
Share on other sites

Okay I see. What if I create that jeep. What name does it have? If the jeep has no name, then there must be another way to refer to that jeep, because the jeep is there. Is that a misunderstanding of the concept?

---------- Post added at 08:18 PM ---------- Previous post was at 08:00 PM ----------

Lets say I want to change this _car variable. Do I then use the setVehicleVarName command?

Share this post


Link to post
Share on other sites

If you're going to need to refer to it later might as well make it global to begin with. Use car instead of _car.

Share this post


Link to post
Share on other sites
If you're going to need to refer to it later might as well make it global to begin with. Use car instead of _car.

While this is true, if your going to be creating lots and lots of cars then you might not want to clutter up the mission namespace.

If your only going to have a few of the objects and then you could just make it global.

Edited by Riouken

Share this post


Link to post
Share on other sites

Don't know if you both have seen my other thread with the "How do I make this automated", but in there I have got a very fine script from a helpfull soul and that script relies on local variables and that seems to mess up the functionality of the script, therefore I am trying to understand these global/local variables a bit better, in the hope of finding a solution. I think the problem lies within a global/local issue. I will try to swap some local variables out with globals and see if I can get that working...

Share this post


Link to post
Share on other sites

After reading your link about the scope of variables I get the idea. The variable only works within the {}; That is also why I can put in (getpos man1), because he is already defined, because he is placed and named in the editor. _pos for the first car is only avalible for scripting within those {}; As soon as it starts to create the second car I have lost the opportunity to use the _pos in the onAct of the trigger created for the first car. Now the question is how to save those _pos variables created for each car and placing them in an array and the bigger question is how to extract those positions for the right cars. Maybe I should split things up, taking the triggers out of the for-command and create them afterwards, but then again I would have the problem of the names of the cars.. Well call me confused..

---------- Post added at 10:04 PM ---------- Previous post was at 09:24 PM ----------

Hmm something that is weird tho is that I can create the cars and then go into the preview of the game and when I use a tool I have to display vehicleVarName is says car1, car2 and so on to all cars. But I am not able to use those names in a setpos (getpos car1)..

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×