Jump to content
Sign in to follow this  
5133p39

essential facts about switches and variables

Recommended Posts

I have searched and found nothing satisfying my following questions. I have become very confused, and even if these questions looks simple to you, i still can't find answers:

1. When i make trigger and put // VARIABLE=true // into it's activation field, what happens?

a.) will the VARIABLE become known to the server?

b.) and what about all the client machines? will they know?

c.) and will there be difference between dedicated/nondedicated server?

(i am not asking about how to use PublicVariable function, i am asking about how OFP triggers works in MP)

2. When i use // P = Player //:

a.) to what will be the P reffering to on dedicated server?

b.) to what will be the P reffering to on nondedicated server?

3. When i execute some script from activation field in trigger, will the script be executed on all of the clients, or only on server machine (dedicated or not)?

(i know i can use the trick with 'Server' logic to ensure the script is running on server/client - that's not the answer to my question)

You may think i am stupid - feel free to do so - but please, answer my questions :-)

Share this post


Link to post
Share on other sites

I am definitely not a source of knowledge on all that is scripting, but I think I may have some hints to the solutions for some of your questions.

Quote[/b] ]1. When i make trigger and put // VARIABLE=true // into it's activation field, what happens?

a.) will the VARIABLE become known to the server?

b.) and what about all the client machines? will they know?

c.) and will there be difference between dedicated/nondedicated server?

(i am not asking about how to use PublicVariable function, i am asking about how OFP triggers works in MP)

Not quite sure about this one. Someone more knowledgeable than I might know. But I think it would be the same as writing VARIABLE = true in a script that executed on all clients (including the server).

Quote[/b] ]2. When i use // P = Player //:

a.) to what will be the P reffering to on dedicated server?

b.) to what will be the P reffering to on nondedicated server?

As far as I know, on a non-dedicated server, player will refer to the host's player unit. On a dedicated server, I don't think player will refer to anything on the host computer (may be wrong on this). On all the clients, player will refer to the local client's player unit. The player variable will be different for each client (corresponding to their own local player units).

Quote[/b] ]3. When i execute some script from activation field in trigger, will the script be executed on all of the clients, or only on server machine (dedicated or not)?

(i know i can use the trick with 'Server' logic to ensure the script is running on server/client - that's not the answer to my question)

Triggers are global or executed on each client, I believe. Game logics are only local to the server. So if you put a line of code into the init field of a game logic, that code will only execute on the server, as far as I know. (although I think it may have a global effect; for instance, CreateVehicle. I may be wrong on that one.)

Quote[/b] ]You may think i am stupid - feel free to do so - but please, answer my questions :-)

I would say those are some pretty tough questions. biggrin_o.gif I'm sorry if I misunderstood any of them and gave a misleading answer.

Share this post


Link to post
Share on other sites
1. When i make trigger and put // VARIABLE=true // into it's activation field, what happens?

  a.) will the VARIABLE become known to the server?

  b.) and what about all the client machines? will they know?

  c.) and will there be difference between dedicated/nondedicated server?

(i am not asking about how to use PublicVariable function, i am asking about how OFP triggers works in MP)

It will be known to both the server and the clients, and there will be no difference between a dedicated/nondedicated server running the mission...

UNLESS, you have the words "PLAYER" or "LOCAL" in the condition/activation fields of the trigger, in that case there most likely will be a difference between the clients/server.

Share this post


Link to post
Share on other sites
2. When i use // P = Player //:

a.) to what will be the P reffering to on dedicated server?

b.) to what will be the P reffering to on nondedicated server?

P should be different on each computer. On each client (or hosting server) it should be the name of player, on a dedicated server it should be an undefined object ("scalar bool array string 0xfcffffef").

The rest of the questions have already been answered i think.

Share this post


Link to post
Share on other sites

Thanks everyone for their answers.

And i have one (hopefully) last question:

If i want to execute some script from within an activation field of some trigger (condition = Player In thisList), and i want the script to be executed ONLY by the client machine whose Player is In the trigger list, would the following work if i put it into the executed script?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? not Player In myTriggerList : Exit

VARIABLE = PLAYER_IDX

(PLAYER_IDX is initialized in script running only on player machine // which is ensured with the help of similar line of code like above // executed from within init field of each Playable unit on map - and each of these units passes a unique number to this script => eg. to PLAYER_IDX)

The problem is, when Player1 enters the area defined by the trigger, it sets VARIABLE to 1

..but when Player2 enters this area, the VARIABLE belonging to Player1 is set to 2, and so on.

I am not sure why - either i have some bug in my script, or this isn't the correct way to do that - it seems the script is executed by every client, and the VARIABLE seems to be global for some reason)

(i'm starting to see triggers not only in my dreams, but also on the street and in my house - and those are especially weird because they are allways upside down, placed on the ceiling. I'm afraid to move right now, because one of them is hanging right above my head, pleeeease help me)

Share this post


Link to post
Share on other sites
Quote[/b] ]If i want to execute some script from within an activation field of some trigger (condition = Player In thisList), and i want the script to be executed ONLY by the client machine whose Player is In the trigger list, would the following work if i put it into the executed script?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? not Player In myTriggerList : Exit

VARIABLE = PLAYER_IDX

It should, although you may want to add a parenthesis or two to that condition (simply for protocol's sake) Like so:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? not (Player In myTriggerList) : Exit

Quote[/b] ](PLAYER_IDX is initialized in script running only on player machine // which is ensured with the help of similar line of code like above // executed from within init field of each Playable unit on map - and each of these units passes a unique number to this script => eg. to PLAYER_IDX)

The problem is, when Player1 enters the area defined by the trigger, it sets VARIABLE to 1

..but when Player2 enters this area, the VARIABLE belonging to Player1 is set to 2, and so on.

I'm not sure what you're trying to do. Could you explain it for me? If you're trying to make a list of player units, and give them variable IDs, I think an array would serve you better for your global variable. After declaring the global variable VARIABLE as an array, by writing "VARIABLE = []" without quotes somewhere early (like init.sqs), your above code might look like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? not Player In myTriggerList : Exit

VARIABLE = VARIABLE + [PLAYER_IDX]

I think you might want to check out the Chain of Command's Network Services script suite, which can be found here.

Also, you can find documents and other neat scripts at this link.

Quote[/b] ](i'm starting to see triggers not only in my dreams, but also on the street and in my house - and those are especially weird because they are allways upside down, placed on the ceiling. I'm afraid to move right now, because one of them is hanging right above my head, pleeeease help me)

You are suffering from a mild case of scriptotitis. If you begin to speak in script code to your family members and friends, please seek a doctor. biggrin_o.gif

Share this post


Link to post
Share on other sites

Just one quick comment on<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? not Player In myTriggerList : Exit

placed at the start of a script...there is one potential problem with using a line like that to break out of the script, problem is that if the check involves a null value the whole line is silently ignored, no error-message and the script will execute...this could possibly happen on dedicated servers in this case - although I do not know for sure.

A crude way around it could be<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(player in myTriggerList) : goto "RunScript"

exit

#RunScript

<main code body>

exit

Share this post


Link to post
Share on other sites

Rune -

Quote[/b] ]problem is that if the check involves a null value

I don't get it - what null value? where it would came from?

Share this post


Link to post
Share on other sites

Eg if you check for "player" on a dedicated server, where there is no player. You would get a null object in return ("scalar bool array string 0xfcffffef" i guess).

Share this post


Link to post
Share on other sites
Eg if you check for "player" on a dedicated server, where there is no player. You would get a null object in return ("scalar bool array string 0xfcffffef" i guess).

Null object = "<NULL-object>" (after the result is converted to string)

"scalar bool array string 0xfcffffef" is returned when reffering to UNINITIALIZED variable.

Share this post


Link to post
Share on other sites

...And both of those will be silently ignored

Share this post


Link to post
Share on other sites
...And both of those will be silently ignored

what do you mean?

Share this post


Link to post
Share on other sites

That if those appear in a condition the whole line is ignored.

Share this post


Link to post
Share on other sites
That if those appear in a condition the whole line is ignored.

I am not sure i understand:

you mean when i put // Format["%1",SOME_VARIABLE] != "scalar bool array string 0xfcffffef" or Format["%1",SOME_VARIABLE] != "<NULL-object>" // to the condition field, then the trigger will not be triggered, even if any of the conditions are true???

...i didn't tested it, but i think it is nonsense. This should work.

Or do you mean when i use them in any condition in script that it is ignored (whole condition is skipped) - that's nonsens definitely, this i have tried long ago and it works.

Share this post


Link to post
Share on other sites
Format["%1",SOME_VARIABLE] != "scalar bool array string 0xfcffffef" or Format["%1",SOME_VARIABLE] != "<NULL-object>"

No, those two will work, but technically the null/nil variables are used in the function 'format' which returns a string, the string is the thing used in the condition...But Anyway I found out that I was wrong... it is actually only the uninitialized variables that get silently ignored, the null ones do not.

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

? (true OR <objNull variable> != player)                                     -> always activates as you might expect

? (true OR <grpNull variable> != group player)                           -> always activates also not surprising

? (true OR <uninitialized or destroyed variable> != <whatever>)  -> never activates(this is what I mean by silently ignored - it causes no error message)

Now I am aware that it has been made to work this way on purpose so that you can set triggers to react on conditions that have not been initialized and that kind of stuff, but if you are not aware of it when scripting it can cause really hard-to-find errors. This is why I am going on and on about it wink_o.gif

If you want to check if groups or objects are null there is no need for the string-check, isNull will do both...but the string check can be used to check if a variable is uninitialized or has been destroyed using <variable> = nil...Should you have a null object or group and you need to find out which, then the string checks("<NULL-object>" vs. "<NULL-group>") will also be useful, but that will be a rare case I guess.

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  

×