Jump to content
Sign in to follow this  
Nightjay0044

Varialbes

Recommended Posts

Hi, I know with variable you can do this for example.

West = true [/code]

Which creates a variable named (West).

You can use that to activate triggers after a certain number of other triggers have been activated, which ever your choice.

With the questions I'm going to ask, could someone give me a step by step with exatly how to do it in the editor format, thanks Here are my questions.

1) In order for the mission to end, all the objectives must be complete, if there not the player must return back to them. How do I make it so if the player doesn't finish his objectives, and reaches the extraction or ending of the mission, how can I make it so he has to go back to get them done?

2) If someone could run the basics by me on variables, that would be great.

That's all I got for now, thanks everyone.

biggrin_o.gif

Share this post


Link to post
Share on other sites

For every objective create a variable.

In the activation field of 1rst obj put: obj1=true

And for the 2nd obj: obj2=true

and so on...

In the condition field of end trigger put: obj1 && obj2 && etc

So all objectives have to be met.

Its also a good idea to declare the variables in your init.sqs as false..

obj1=false

obj2=false

And then the triggers will make them true.

Hope it helps.

Share this post


Link to post
Share on other sites
West = true

ooh, bad example smile_o.gif

west is a static value and defines the side west.

Other than that, there are different types of variables:

<span style='font-size:11pt;line-height:100%'>Variable types</span>

1) Numbers

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

Numbers (float) in OFP can have up to 6 counts after the comma, if I'm not mistaken. You can use the mathematical operations + (plus), - (minus), / (divided by), * (multiplicate), ^ (raise to the power of) and % (modulo). There are also the functions exp, abs, sin, cos, asin, acos, tan, atan, atan2, log and ln concerning numbers.

2) Booleans

Booleans are sort of switches and can have two different values: true and false

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

You can check a bool with either

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">; does _var match true?

? (_var) : ...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">; does var match false ?

?!(_var) : ...

You can use && (and) and || (or) to connect comparisons of multiple booleans.

3) Strings

Strings are variables containing simple text.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_var = "Hello world"

You can combine strings with the + operator.

4) Arrays

Arrays contain multiple values.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array = [1,2,"bla",76,true,5,3]

Arrays can contain any types of variables. The index of the first element is 0, you can select the elements by using select and set them by using set.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array = [1,2,"bla",76,true,5,3]

_array select 2

; => returns "bla"

_array set [2, "boo"]

; => replaces "bla" with "boo"

You can connect arrays using + or substract them using -

<span style='font-size:11pt;line-height:100%'>Generic operations</span>

Use the single = operator to assign a value to a variable.

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

If you want to compare the variable with a specific value or variable, use the double ==

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? (_var==1) : player sideChat "_var is 1"

You can also use <, >, <= and >= on numbers.

<span style='font-size:11pt;line-height:100%'>Local vs. global</span>

Local variables start with an underscore (_) and can be accessed in the current script only. Such variable names can't be used in the editor.

Thus, if you define the variable _var in scriptA.sqs and query _var in scriptB.sqs, you'll get the result of non-existent (unless you have defined it before in scriptB.sqs).

Global variables don't start with an underscore (surprise) and can be accessed and modified from anywhere on the same client (computer). So you can change or query such a variable (e.g. var) from within triggers, scripts or whatever.

Note that in MP games such variables still are local to the certain client you defined them on, until you use the command publicVariable. Then the variable will be synchronized on all clients / the server and then will be local again until you use the very same command again.

Share this post


Link to post
Share on other sites

Basic thing, but easy to forget: conditionals use two equals signs, not one. So if you wanted to fire the trigger when _NUnits was 9, then:

_NUnits == 9

and not

_NUnits = 9

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  

×