Jump to content
Sign in to follow this  
Psycho1

Problem creating a public variable

Recommended Posts

I'm using Karrillion's vehicle respawn scripts, and I wanted to create a public variable that equals one of the local variables in the script. The reason I want to is because I need to use the variable in a trigger. This is what I tried:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_armortypelist=["Bradley","BMP2","M1Abrams","T80"]

_boattypelist=["BoatE","BoatW"]

_vehicletypelist=_vehicletypelist+_armortypelist+_boattypelist

armor = _armortypelist

PublicVariable "armor"<span id='postcolor'>

The reason I did it that way is because I just looked at a C&H scoring script that had a public variable, and that's how they did it and it works. But when I try this method out, I get "expected Bool" when I run the mission, and it shows "armor=_armortypelist" right before it says "expected Bool". I left out the "PublicVariable armor" and the same thing happens.

Share this post


Link to post
Share on other sites

hmm - not sure, but this looks like armor expects true or false.

Try using another variable-name instead of armor, maybe it's

a reserved boolean string in the game and decides wether

a unit has or has not armor abilities.

Sorry, but i can't test it out myself right now, i'm at work.

Share this post


Link to post
Share on other sites

You were right, I replaced "armor" with the name "tanks" and it works just fine. Thanks again.

Share this post


Link to post
Share on other sites

I jumped the gun:( It wasn't the script causing the error, it was the trigger. I thought it was fixed since I didn't get that expected bool thing, but when I put the trigger back in I got the same message:( The variables are okay, it's just the trigger I'm messing up.

I scratched out the tanks variable because that would select all tanks. I want the trigger to execute only on a tank if it goes in a specific trigger defined area. So I grabbed the local variable _vcl(which wouldn't group all vehicles together) and declared a public variable "vcl2" that equaled it. Here is the important stuff I put in the trigger:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> activationBy="ANY";

repeating=1;

age="UNKNOWN";

expCond="vcl2";---this is wrong-I get the message "error type object, expected Bool"

expActiv="this setpos [(getpos this select 0), (getpos this select 1), (getpos this select 2)+ 2]";

class Effects

{

};

synchronizations[]={};<span id='postcolor'>

Share this post


Link to post
Share on other sites

If expCond means condition than the variable vcl2 shold be true or false.

If you want check if a tank is in area and you have array of tanks, just create invisible H in center of area and make script whitch checks distance between center H and tanks.

Share this post


Link to post
Share on other sites

Are you sure I can't get this to work using a trigger? It would have been very convenient if you could enter variables for the activated by field. Couldn't I get it to work if I put something to the affect of "vcl2 inarea" for the Condition field. That's not the correct syntax you would use, just trying to get you to see what I mean. Is it possible to enter something like that in the Condition field?

Share this post


Link to post
Share on other sites

I know what you mean. It would be nice to have command like inarea, but it doesn't exist.

You can try condition vcl in thislist. But this shoud be working with objects not with types of objects.

Share this post


Link to post
Share on other sites

I tried that vcl in thislist and I got error type bool, expected object.  I guess I'll try a script to get it to work.  I've only just started messing with scripts, so I'll need some help doing it though.  I'll need to use both x and y values I guess because the area I want the tank affected by the action is pretty strict.  Here is how I would start it out:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Object=_this select 0

_xval=Getpos _Object this select 0

_yval=Getpos _Object this select 1

_zval=Getpos _Object this select 2

_invisiblehxval=Getpos invisibleh this select 0

_invisiblehyval=Getpos invisibleh this select 1

#start

?(_xval < _invisiblehxval + 5) and ?(_yval < _invislbehyval + 5)or ?(_xval < _invisibleh - 5) and ?(_yval < _invisiblehyval - 5) : Goto "actions"

Goto "start"

#actions

this setpos _Object [(getpos this select 0), (getpos this select 1), (getpos this select 2)+ 2]

Goto "start"<span id='postcolor'>

I know I have made some errros wit hthat script, plz let me know what you can find in it.  The invisibleh public variable is the name of the invisibleh.

I'm pretty sure I made an error with those and or commands. I don't know if you can group them all together like that. What I was trying to do is have it goto actions if either 2 sets of instructions worked out. If I need to be more clear, let me know.

Share this post


Link to post
Share on other sites

Detecting the position of the tanks relative an object is a pain in the ass for what I'm trying to do. The x value is easy, but the yval is gonna be a real pain. I want the script to activate when the tanks are within a very long but not wide rectangular zone. If I have the script activate if it is within a certain yvalue + whatever, it will only work if it is exactly north or south of the invisibleh(I think). I hope I'm being clear, I'm tring to at least, but it's hard to explain, hehe.

For the triggers in the mission.sqm, it uses this to determine the boundaries of the trigger:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">position[]={7893.171387,37.892941,3746.503662};

a=270.000000;

b=450.000000;<span id='postcolor'>

Now.....does the a=270 mean the position x value + 270 and x value - 270 to create the up to down lines(boundaries) of the trigger area?

And b=450 means y value + 450 and yvalue - 450 to create the left to right boundaries? Couldn't I use these numbers in a script to pretty much replicate the way an area is defined for a trigger in the mission editor? Than use if then statements to see if _vcl is within the area of the replicated trigger? I'm stumped on how to exactly do it though:(

Share this post


Link to post
Share on other sites

Here is repaired script (I repaired only syntax not functionality):

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Object=_this select 0

_xval=(Getpos _Object) select 0

_yval=(Getpos _Object) select 1

_zval=(Getpos _Object) select 2

_invisiblehxval=(Getpos invisibleh) select 0

_invisiblehyval=(Getpos invisibleh) select 1

#start

?(_xval < _invisiblehxval + 5) and (_yval < _invislbehyval + 5)or (_xval < _invisibleh - 5) and (_yval < _invisiblehyval - 5) : Goto "actions"

Goto "start"

#actions

this setpos _Object [(_xval), (_yval), (_zval)+ 2]

Goto "start"

<span id='postcolor'>

- In #action you only place object 2 meters above groud. You don't need to read object's position beacuse you did it the beginning of script. (you read _xval,_yval,_zval of object).

May be better should be don't use only invisibleH named invisibleh but use whichever object you enter as script parameter. So rewrite 5th and 6th line of script to

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_ih = _this select 1

_invisiblehxval=(Getpos _ih) select 0

_invisiblehyval=(Getpos _ih) select 1<span id='postcolor'>

and you will execute this script by [objectName,invisHname] exec "scriptName.sqs"

- If you use neverending loop in script place delay command (~delayInSeconds) before goto. If delay command isn't in loop script is slowing down whole game too much. Place for example ~5 if you guard big area or ~0.2 if the area is small.

- If you want check spheric (or circle) area you don't need ivisible H's position and condition is simple :

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Object=_this select 0

_xval=(Getpos _Object) select 0

_yval=(Getpos _Object) select 1

_zval=(Getpos _Object) select 2

_ih = _this select 1

#start

?(_object distance _ih)<5:goto "actions"

~0.5

goto "start"

#actions

this setpos _Object [(_xval), (_yval), (_zval)+ 2]

~0.5

Goto "start"

<span id='postcolor'>

If you want to guard not wide rectangular zone you need XY coordinates of invisible H and condition will be more complex.

I use new variables _North,_South, _East and _West. Their value is distance (I think in meters) from invisible H.

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Object=_this select 0

_xval=(Getpos _Object) select 0

_yval=(Getpos _Object) select 1

_zval=(Getpos _Object) select 2

_ih = _this select 1

_ihxval=(Getpos _ih) select 0

_ihyval=(Getpos _ih) select 1

_N=5

_S=10

_E=6

_W=7

#start

? (_xval >=(_ihxval-_W)) and (_xval <=(_ihxval+_E)):goto "NS"

~0.5

goto "start"

#NS

? (_yval >=(_ihyval-_S)) and (_yval <=(_ihyval+_N)):goto "actions"

~0.5

goto "start"

#actions

this setpos _Object [(_xval), (_yval), (_zval)+ 2]

~0.5

Goto "start"

<span id='postcolor'>

If you want air units to be undetected by this script change first condition (after #start) to :

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">?? (_xval >=(_ihxval-_W)) and (_xval <=(_ihxval+_E)) and (_zval < 2):goto "NS"<span id='postcolor'>

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Psycho1 @ Mar. 30 2002,14:00)</td></tr><tr><td id="QUOTE">I want the trigger to execute only on a tank if it goes in a specific trigger defined area.<span id='postcolor'>

Let me suggest an alternative approach to this: you can simply count tanks (or vehicles matching any criterion you like) in trigger area (which can be rectangular or eliptic). As this will use ingame detection of what is in trigger area and what not, it will be much more effective.

Basic type-detection code would look like:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

"tank" countType thislist

<span id='postcolor'>

If you need any more advanced condition, you can use something like:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

"""tank"" countType [_x]>0 and side _x == East" count thislist >0

<span id='postcolor'>

Explanation: to test if vehicle is of any given type, create an array containing just this vehicle and count vehicles of given type in that array. Loop this over all members of thislist and check count of elements that pass your critetion.

(Note: you need at least 1.43 to be able to parse double quote marks in expression above).

Share this post


Link to post
Share on other sites

To demonstrate my suggestion I attach source of mission (Intro island) that contains sensor which is activated by East tanks present but not by East soldier. You can easily change it by modifying basic trigger functionality, like changing mode from "Present" to "Detected by West", from activated by "Anyone" to activated by "East" etc.

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

version=11;

class Mission

{

addOns[]={};

randomSeed=13926403;

class Intel

{

};

class Groups

{

items=3;

class Item0

{

side="WEST";

class Vehicles

{

items=1;

class Item0

{

position[]={9492.439453,29.834999,4020.639893};

azimut=85.000000;

id=0;

side="WEST";

vehicle="SoldierWB";

player="PLAYER COMMANDER";

leader=1;

skill=0.600000;

markers[]={};

};

};

};

class Item1

{

side="EAST";

class Vehicles

{

items=1;

class Item0

{

position[]={9815.640625,26.730000,3995.041016};

id=1;

side="EAST";

vehicle="BMP";

leader=1;

skill=0.600000;

markers[]={};

};

};

class Waypoints

{

items=2;

class Item0

{

position[]={9818.839844,26.730000,4068.640137};

synchronizations[]={};

class Effects

{

};

showWP="NEVER";

};

class Item1

{

position[]={9866.839844,26.730000,3998.240723};

type="CYCLE";

synchronizations[]={};

class Effects

{

};

showWP="NEVER";

};

};

};

class Item2

{

side="EAST";

class Vehicles

{

items=1;

class Item0

{

position[]={9828.439453,26.730000,3953.440186};

azimut=85.000000;

id=2;

side="EAST";

vehicle="SoldierEB";

leader=1;

skill=0.600000;

markers[]={};

};

};

};

};

class Sensors

{

items=1;

class Item0

{

position[]={9831.639648,26.730000,3982.240234};

activationBy="ANY";

repeating=1;

age="UNKNOWN";

name="ta";

expCond="""""""tank"""" countType [_x]>0 and side _x == East"" count thislist>0";

class Effects

{

};

synchronizations[]={};

};

};

};

class Intro

{

addOns[]={};

randomSeed=11330563;

class Intel

{

};

};

class OutroWin

{

addOns[]={};

randomSeed=8472579;

class Intel

{

};

};

class OutroLoose

{

addOns[]={};

randomSeed=3976707;

class Intel

{

};

};

<span id='postcolor'>

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Suma @ Mar. 31 2002,16:00)</td></tr><tr><td id="QUOTE"></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">"tank" countType thislist<span id='postcolor'>

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">"""tank"" countType [_x]>0 and side _x == East" count thislist >0

<span id='postcolor'><span id='postcolor'>

More explanation please :

"tank" is string (values are from official scripting refererence - String Values - Vehicle)

side _x == East => _x is unit - but where I get a value ? Is similar like "_x blabla" foreach blabla ?

Am I understand it right ?

Share this post


Link to post
Share on other sites

I made a trigger with:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">"tank" countType thislist<span id='postcolor'>

as the condition, and I get this error message: "Error type number, expected Bool." Bool meaning true or false right?.....doesn't everything have to be true or false for the condition than? How would "tank" countType thislist work in the Condition field?

Share this post


Link to post
Share on other sites

Use condition :

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">"""tank"" countType [_x]>0" count thislist>0<span id='postcolor'>

condition must be always true or false

Share this post


Link to post
Share on other sites

Well, I got the condition field working the way I want it to. The reason I can tell is because when I enter the trigger defined area with a tank, I get an error message about my activation field. The good news is that all my tanks are being detected by the trigger.

In the activation field, I put:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">this setpos [(getpos this select 0), (getpos this select 1), (getpos this select 2)+ 2]<span id='postcolor'>

and I tried it with the variable "tanks" in place of "this" too....both give me the same error message...."Error type Bool, expected Object". How is that interpreted as a true or false statement when all it is doing is getting the x,y,z values of the tank and adding 2 to the z value? I fail to see why it thinks it is a Bool statement.

Other than the activation field, it is detecting the tanks for both East and West the way I want it to. Now if I can fix up the activation field, hopefully I can get my task accomplished.

Share this post


Link to post
Share on other sites

If you use

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">"_x setpos [(getpos _x select 0), (getpos _x select 1), (getpos _x select 2)+ 2]" foreach thislist<span id='postcolor'>

then it moves 2 meters above ground all units in trigger area. The problem is to find how to pick tanks from array of various units. Maybe some script ?

Here is the script :

In trigger on activation place :[thislist,"tank"] execute "nameOfScript.sqs"

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_units= _this select 0

_type = _this select 1

_i=count _units

#loop

_unit = _units select _i-1

?(_type countType [_unit]>0):goto "actions"

goto "afteractions"

#actions

_unit setpos [(getpos _unit select 0), (getpos _unit select 1), (getpos _unit select 2)+ 2]

#afteractions

_i=_i-1

?_i>0:goto "loop"

exit<span id='postcolor'>

It doesn't work for 100%, I don't know why.

Share this post


Link to post
Share on other sites

I just tested it and it seems to work almost the way I want it to. The problem is that it will add the 2 meters to the tanks z value for a brief second...than it will drop back to the ground even if it is still in the trigger area. I want to maintain that z value + 2 at all times if it is in the trigger area. You might be asking why I want to have tanks floating above ground.....they won't actually appear to be floating above ground, I want to make it look like the tank is traveling over an object....but without the adjusted z value, the tank will bounce around on the object. So I want to create the illusion that the tank is traveling over the object, having it hover just slightly over the object.

I am so very close to getting this task done, all I need to do is have the trigger adjust the z value at all times for the tank if it is within the trigger area.

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Psycho1 @ April 01 2002,03:25)</td></tr><tr><td id="QUOTE">The problem is that it will add the 2 meters to the tanks z value for a brief second...than it will drop back to the ground even if it is still in the trigger area.  I want to maintain that z value + 2 at all times if it is in the trigger area.  <span id='postcolor'>

I am afraid you cannot achieve what you want in trigger. Trigger is not evaluated in each frame - this would cost too much CPU. If you really need to have floating tanks, you have to use script for floating - but be advised that it can have significant performance impacts. Floating tanks may also have very limited functionality - if simulation thinks tank is not colliding with ground, it may easily happen tank will not be able to move.

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Psycho1 @ April 01 2002,00:08)</td></tr><tr><td id="QUOTE">In the activation field, I put:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">this setpos [(getpos this select 0), (getpos this select 1), (getpos this select 2)+ 2]<span id='postcolor'>

and I tried it with the variable "tanks" in place of "this" too....both give me the same error message...."Error type Bool, expected Object".  How is that interpreted as a true or false statement when all it is doing is getting the x,y,z values of the tank and adding 2 to the z value?  I fail to see why it thinks it is a Bool statement.<span id='postcolor'>

this is evaluated as default result of trigger in all trigger fields (true or false). You therefore cannot write getpos this or this setpos .....

Share this post


Link to post
Share on other sites

Oh man, that is a bummer:( What I did was make an actual bridge using the building "housegaraz_bez_tanku". I adjusted the z values for each one so that they were perfectly aligned and just the top part showed up above the water. It really does look like a bridge, and infantry can move across it no problem. But if a tank tries to go on it, it bounces all over:( That's why I wanted to adjust the z values of the tanks when it was over the bridge. The tank bouncing isn't that bad though, I just might be able to get by with it.

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  

×