SpitShine 10 Posted May 4, 2014 tank = obj1 if (isserver) then { tank setdir 20; }; Why does tank return an undefined variable error in the above situation? Share this post Link to post Share on other sites
mikie boy 18 Posted May 4, 2014 if the error is not the syntax, then it depends on a few things. if obj1 is not an object on the server already loaded in before script runs, then the script will not know what obj1 is. if obj1 is an actual object on the server, and the program you are running runs after the mission file is instantiated, then its should identify obj1 and a global variable to the object you named. Therefore it should work (syntax ; aside). additionally tank is a global variable - so why do you need to reference another global variable. you should use _tank tank to save on memory when this particular script finishes. cant you just use if (isserver) then { obj1 setdir 20; }; Share this post Link to post Share on other sites
SpitShine 10 Posted May 4, 2014 No can do, because tank is not a pre-placed unit, it is spawned by one script and then given further variables by another script. But the later script returns tank as an undefined variable even if it spawns before the later script is run. ---------- Post added at 23:52 ---------- Previous post was at 23:42 ---------- Oh and guess what on another mission an actual honest to goodness pre-placed object is somehow an undefined variable when a script attempts to reference it isn't that just grand? Share this post Link to post Share on other sites
Belbo 462 Posted May 5, 2014 (edited) if (isServer) then { waitUntil {!isnil "obj1"}; //that way you make sure your _tank variable is defined and only defined as soon as obj1 is present. _tank = obj1; _tank setdir 20; }; obj1 has to be the name of the object, not the classname. alternatively you can try: if (isServer) then { if (isNil "obj1") then { //but make sure that obj1 will sooner or later be present. waitUntil {!isnil "obj1"}; _tank = obj1; _tank setdir 20; }; }; Edited May 5, 2014 by Pergor Share this post Link to post Share on other sites
terox 316 Posted May 5, 2014 if the script that spawns the tank is not on the same node as the script that also uses the tank variable, then you will need to pv "tank" or pv "obj1" also code like waituntil {! Isnil "Tank"}; could be used. As far ans the undefined variable issues are concerned, you are doing something wrong, making a logical assumption that is incorrect. Share this post Link to post Share on other sites
SpitShine 10 Posted May 5, 2014 >you will need to pv "tank" or pv "obj1" how? Share this post Link to post Share on other sites
Belbo 462 Posted May 5, 2014 >you will need to pv "tank" or pv "obj1"how? https://community.bistudio.com/wiki/publicVariable waitUntil {!isNil "obj1"}; tank = obj1; publicVariable "tank"; Share this post Link to post Share on other sites
DasClark 10 Posted May 5, 2014 I am guessing here, but I think that Terox is saying that you need to pass the variable name for the tank into the public domain after it is created (otherwise, your script can't figure out the name of the dynamically created tank). For instance... MyMakeATankScript.sqf // gonna make a tank and let the world know... myTank = "B_MBT_01_cannon_F" createVehicle (position player); publicVariable ("myTank"); MyUseTheTankNameToPointItNorthEastish.sqf if (isServer) then { waitUntil {!isnil "myTank"}; //that way you make sure your _tank variable is defined and only defined as soon as obj1 is present. _tank = myTank; _tank setdir 20; }; although they are right, you could just use myTank in the script. The only reason to cast it to another name is if you are passing it different tank names as a param and don't want a script per tank name. DasClark Share this post Link to post Share on other sites