Jump to content
Sign in to follow this  
daza

Publicvariable error

Recommended Posts

I've used Public Variables successfully in the past, but have had trouble with them lately.

bob1=true; 
PublicVariable "bob1";
vpciv1 sidechat "Waiting for further instructions sir";
dostop vpciv1;

I have another script that loops for civillian to follow player until bob1 becomes true. And the player does that by activating the little script (see above) through an addaction.

But i get an error in the debug mode saying missing ; on line 2.

A similar problem i had with putting a publicvariable into a trigger, the editor accepted it, but if i tried to change the radius of the trigger after setting it up, it would do the same thing, say there was a ; missing.

So why am i getting an error when it looks correct?

Share this post


Link to post
Share on other sites

Hm, a wrong encoding maybe? I can't see a syntax mistake. Which editor do you use to make scripts?

Share this post


Link to post
Share on other sites

I just use notepad.

**Update**

I added an = to the line.

So its publicvariable="bob1";

Now i dont get any error messages about it. Yet in wiki the example doesn't have an =

Edited by Daza

Share this post


Link to post
Share on other sites

After fixing the error problem. My script works up to a point,

when the publicvariable becomes true (after another script is called which makes the variable true) the script below moves onto next bit where the civ stops following as it suppose to do.

But when the script(below) is called again, after the variable has been reset back to false. It somehow seems to remain true. And the unit remains where it is, saying "I'll wait here sir." evertime i run the script via addaction.

Why wont it work?

vpciv1 setunitpos "up";
while {isnil "bob"} do
{
sleep 1;vpciv1 domove getpos player;
};
vpciv1 globalchat "I'll wait here sir.";
dostop vpciv1;
sleep 1;
bob=false;
publicvariable="bob";

Share this post


Link to post
Share on other sites

That's not how you use a public variable, no equals... Like you did in the first post.

http://community.bistudio.com/wiki/publicVariable

What you're doing above is setting the global variable to false, then making a new global variable called publicvariable with a string containing "bob". Rather confusing ;)

Personally I would advise looking up this instead:

http://community.bistudio.com/wiki/setVariable

Sort of the same as publicVariable, but you attach it to an object instead (unit, object, game logic, trigger, whatever). I've found it easier to grasp the concept of this rather than the generic publicvariable floating in the public space. In your case, the civilian would hold a variable telling him to either follow or stay put.

Share this post


Link to post
Share on other sites

I assume that since you are trying to make a follow script, the civ is an AI and not grouped with the player. Thus, it's local to the server. So, run this on server:

"BOB" addpublicvariableeventhandler {
 _this = _this select 1;
 switch (_this select 0) do {
   case "move": {
     shCiv1 = (_this select 1) spawn {
       while {alive vpciv1} do {
         vpciv1 domove getpos _this;
         sleep 3;
       };
     };
   };
   case "stop": {
     terminate shCiv1;
     vpciv1 globalchat "I'll wait here sir.";
     dostop vpciv1;
   };
 };
};

Then you can just order him around from pretty much anything (triggers, actions etc).

Make him move to an object (player in this example):

BOB = ["move",player];
publicvariable "BOB";

Make him stop:

BOB = ["stop"];
publicvariable "BOB";

Share this post


Link to post
Share on other sites

Thanks Shk for your help. Yes you are right its a simple script for a non-grouped to player civ AI to follow a player and stop. (This is for a MP game)

I originally had this civ unit grouped to the player who finds the civ. But if he is killed, no other player could regroup the unit to them, the civ would run off looking for the leader of the group. So i thought i will have to make a basic follow, stop script that any player on the side who is protecting the civilian

can give her orders to follow them, incase of causalities. I would like to include move to where i am pointing, like you can do when u have a squad under your command.

anyway...

I'm not too sure when the addpublicvariableeventhandler is suppose to be called, whether just once at the start of the map(which im presuming).

So i had that eventhandler script run/called in the init.sqs file.

And i added if (!isServer) exitWith {}; to the top of the script.

When i tested it, i got an error for the move code u gave, line 2 missing ;

BOB = ["move",player];
publicvariable "BOB";

Yet there is no missing ;

Share this post


Link to post
Share on other sites

It should be init.sqf. That's why your getting that error. Your using old style script format (init.sqs) with the new execVM script format.

Share this post


Link to post
Share on other sites
It should be init.sqf. That's why your getting that error. Your using old style script format (init.sqs) with the new execVM script format.

Made the change to .sqf

But i still get the same error as before, the publicvariable line is missing a ;

Share this post


Link to post
Share on other sites

Well, I tested the code in utes, works. There's something else you have going on.

Share this post


Link to post
Share on other sites

You shall not overwrite script commands by creating a global variable which has the same name as a script command. Check all your scripts and trigger codes for that again, because overwriting publicvariable first (like you tried and actually did in your 3rd post)

publicvariable="bob";

and then trying to use it the as scripting command, causes the exact same error message, as the one that arma2 is throwing at you.

Edited by dengibtsschon

Share this post


Link to post
Share on other sites

Another question regarding Publicvariable in MP.

Are you able to switch a declared publicvariable from true to false and then back to true again? without limit.

Because it doesn't seem to work. I have a script im writing for loading supplies, and the player/truck has to go to drop off point before he can load supplies from the same loading point as before. With the Publicvariable i can get it to stop the player from loading more supplies on if he hasnt been to the drop off point. However, once he has i want to reset the publicvariable so he's free to get more supplies.

Share this post


Link to post
Share on other sites

hmm..ok..

With my load zone after completed a loading supplies, it sets a publicvariable to true, which is not the condition to allow loading. So player is told Supplies already aboard.

(That works) You can load supplies (which is just a tally number at the moment) and if you try to load again, you get the message about supplies already aboard. Thats all cool.

Once unloading happens at the supply drop off/zone, i set all publicvariables to false so the supply zones condition would be met and open. But it i cannot load new supplies again.

So i tested it using the same method pretty much, with setvariable and it works as its meant to.

So why didn't it work with PublicVariable?

Example of what im doing...with PV.

Loading Zone script:

_orgpos = position player;

if (!isnil "supplydone") then
{
Hint "Supplies already have been loaded.";
}
else
{

if (typeof vehicle player == "WarfareSupplyTruck_USMC") then
{
titleText ["Loading PROGRESS:[|         ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["Loading PROGRESS:[||        ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["Loading PROGRESS:[|||       ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["Loading PROGRESS:[||||      ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["Loading PROGRESS:[|||||     ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["Loading PROGRESS:[||||||    ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["Loading PROGRESS:[|||||||   ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["Loading PROGRESS:[||||||||  ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["Loading PROGRESS:[||||||||| ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["Loading PROGRESS:[||||||||||]COMPLETE", "PLAIN DOWN"];


};
if (position player distance _orgpos > 10) exitwith
	{
titleText ["Loading PROCESS ABORTED", "PLAIN DOWN"];

};

titleText ["Loading Process COMPLETE", "PLAIN DOWN"];


spw=spw+1;
hint format ["Current Onboard Supply Point Tally is: %1", spw];

supplydone = "true";
publicvariable "supplydone";


};

Unloading Zone Script:

_orgpos = position player;

If (spw<1) exitwith {hint "You don't have supplies onboard!";};

if (typeof vehicle player == "WarfareSupplyTruck_USMC") then
{
titleText ["UnLoading PROGRESS:[|         ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["UnLoading PROGRESS:[||        ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["UnLoading PROGRESS:[|||       ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["UnLoading PROGRESS:[||||      ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["UnLoading PROGRESS:[|||||     ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["UnLoading PROGRESS:[||||||    ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["UnLoading PROGRESS:[|||||||   ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["UnLoading PROGRESS:[||||||||  ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["UnLoading PROGRESS:[||||||||| ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["Loading PROGRESS:[||||||||||]COMPLETE", "PLAIN DOWN"];
};

if (position player distance _orgpos > 10) then
			{
titleText ["UnLoading PROCESS ABORTED", "PLAIN DOWN"];

} else
{
titleText ["UnLoading Process COMPLETE", "PLAIN DOWN"];
};

Gwsupplytally= Gwsupplytally + spw;

hint format ["Current Total Supply Point Tally is: %1", Gwsupplytally];

spw=0;

supplydone = "false";
publicvariable "supplydone";

supplydone2 = "false";
publicvariable "supplydone2";

supplydone3 = "false";
publicvariable "supplydone3";

supplydone4 = "false";
publicvariable "supplydone4";

truck1 setVariable ["loadsupply", 0, true];

null=[gwsupplytally] execvm "spmarkerupdate.sqf";

Share this post


Link to post
Share on other sites
if (!isnil "supplydone") then

After it's set the first time, it will always return true. Doesn't matter if it's set true or false, it's still not nil after that.

Share this post


Link to post
Share on other sites
After it's set the first time, it will always return true. Doesn't matter if it's set true or false, it's still not nil after that.

Ok i understand the problem now. Is there another way i can write it, so it will work? the command reference for True doesn't give any examples.

I've only come across in my search a .sqs example someone gave, which was

?(truck): goto "end"
?!(truck) goto "loop" 

But i only write scripts in .sqf format.

Thanks.

I can use the setvariable method, but it would be good to learn how to properly use publicvariable in this way too. Unless when you keep altering

a variables true and false its better to use setvariable...?

Share this post


Link to post
Share on other sites

For globals, use a prefix such as: DAZ_bob1

Also, sometimes its better to be descriptive, such as DAZ_waitbob1, so that you don't mistakenly reuse a variable again for something else.

Using isNil saves you the trouble of defining the variable beforehand. You can make a variable Nil again by doing: DAZ_waitbob1 = Nil;

Or you can use the usual method of checking if a variable is true or false.

Init.sqf:

DAZ_waitbob1 = false;

if(DAZ_waitbob1) then {

//waiting

} else {

//not waiting

};

Keep in mind, that the locality of the unit will change if it moves from one player's group to another. Variables affecting the unit will be left of the old player's computer unless you've already used publicVariable.

Share this post


Link to post
Share on other sites
For globals, use a prefix such as: DAZ_bob1

Also, sometimes its better to be descriptive, such as DAZ_waitbob1, so that you don't mistakenly reuse a variable again for something else.

Using isNil saves you the trouble of defining the variable beforehand. You can make a variable Nil again by doing: DAZ_waitbob1 = Nil;

Or you can use the usual method of checking if a variable is true or false.

Init.sqf:

DAZ_waitbob1 = false;

if(DAZ_waitbob1) then {

//waiting

} else {

//not waiting

};

Keep in mind, that the locality of the unit will change if it moves from one player's group to another. Variables affecting the unit will be left of the old player's computer unless you've already used publicVariable.

Thanks Tcp for your example, I'm getting a better grasp of variables now.

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  

×