OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: L!nk on 13 Apr 2008, 16:24:28

Title: publicVariable thoughts...
Post by: L!nk on 13 Apr 2008, 16:24:28
Will this work? ???

Code: [Select]
"variable1" addPublicVariableEventHandler {publicVariable "variable1"};
Will it broadcast the variable once its changed? (can't really test this on one computer) If true, whats the performance diffrence between this way and the old way?

Then I just have to add this line once and not publicVariable "variable1" everytime I change a variable that needs to be broadcasted.

This can easily reduce problems when scripting multiplayer missions. :scratch: I'm just not sure if it will work.

Please confirm this for me. :good:

Thx,
L!nk
Title: Re: addPublicVariableEventHandler thought...
Post by: i0n0s on 13 Apr 2008, 17:34:59
This won't work.
addPublicVariableEventhandler will call if the variable has been broadcasted.
publicVariable "variable1" will raise the eventhandler on all other machines (not the computer were the line was executed).
So you have to manually broadcast, but know you can easily check if the var has been broadcasted.
Title: publicVariable thoughts...
Post by: L!nk on 20 Apr 2008, 13:02:47
I have another question concerning publicVariable command.

Check this out.
Code: [Select]
_ruin = _ruinType createVehicle [0,0,0];
_final = _finalType createVehicle [0,0,0];
_ruin setpos _pos;
_ruin setdir _dir;
sleep _time;

deletevehicle _ruin;
_final setpos _pos;
_final setdir _dir;

What happens is:
1. A ruin is created at pos [0,0,0]
2. The building of the ruin is created at pos [0,0,0]
3. The ruin is moves to location A.
4. The ruin turns in a direction
5. Time passes
6. Ruin is deleted
7. Building is move to location A
8. Building turns in a direction

Here is my problem:
When client A runs this script. He sees the ruin for 0.5 secs before it disapears. When time runs out, the building appears.
This only happens when client A runs the script.
When client B runs it, everything works and appears perfectly.

What happend to the ruin?
Title: Re: publicVariable thoughts...
Post by: Loyalguard on 20 Apr 2008, 14:34:48
We need more info before trying to diagnose this.  How are the scripts on each client being executed?  Are they executing at the same time?  Where are they being executed?
Title: Re: publicVariable thoughts...
Post by: L!nk on 20 Apr 2008, 15:53:53
The script is executed as soon as the client double clicks on a entry of a list. The dialog closes and this script is run.

Also notice that the returned object for the building has "REMOTE" added at the end.

hint format ["%1",_final] returns:
Code: [Select]
"8726a98# 638415: budova_in.p3d REMOTE"
Title: Re: publicVariable thoughts...
Post by: Rommel92 on 20 Apr 2008, 23:03:09
Somehow I think "REMOTE" means its CLIENTside only?  :confused:
Could you still please post the code your using to execute, precisely, because it appears you have more then one argument in play here so... (_ruinType etc).
Title: Re: publicVariable thoughts...
Post by: Loyalguard on 20 Apr 2008, 23:16:23
I am still taking it all in, but, one thing for sure to avoid is using the keyword _time (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=t#369)  It is a reserved variable that counts the time passed since the script began running.  You should use another identifier for your sleep time variable (e.g. _waitTime).  Maybe that is what is screwing up the script.
Title: Re: publicVariable thoughts...
Post by: Rommel92 on 20 Apr 2008, 23:24:52
Quote
_time

Didn't know that...

Does that mean if you had a script that just looped per say, you could use the _time variable to act as a timer if you made it GLOBAL and some point in a loop, saves code I spose...  :clap:
Title: Re: publicVariable thoughts...
Post by: Loyalguard on 21 Apr 2008, 01:29:20
I imagine so Rommel.  Something like this maybe (assuming global value)?

timer.sqf
Code: [Select]
while {true} do
{
     timeElapsed = round (_time); // Most likely not an integer so round it to one.
     sleep 1;
};

Title: Re: publicVariable thoughts...
Post by: h- on 21 Apr 2008, 06:58:11
Two things about _time:

1. If you define such an variable in the start of the script it no longer gives you the time the script has run, just the value yo have given to it.
2. Don't know at which point BIS has 'fixed' it but at least pre-1.09 _time didn't work in sqf; gave an error, now it outputs the scalar bool array pioyugpoydfpgoidyfgpiudfy thingy instead..
Title: Re: publicVariable thoughts...
Post by: Rommel92 on 21 Apr 2008, 11:07:50
There is a global variable "time" as I have since found out, works in any format, however it is SINCE MISSION START.

Code: [Select]
player globalchat format ["%1 SINCE MISSION START",time];
Title: Re: publicVariable thoughts...
Post by: L!nk on 21 Apr 2008, 19:57:36
Aha ok. I found my problem, but I still don't know how to fix it.

When I run this script for the first time in the mission, I work perfectly.

But when I client runs it at the same time the other client runs it, then the ruin disappears. Why is this happening?

I thought that when a client runs a script, the script is local to him.

So, to sum up, client1's script interupts client2's scripts when run while waiting time is active (sleep _time;)

Does it have something to do with the way each client runs the script?

L!nk out!
Title: Re: publicVariable thoughts...
Post by: Rommel92 on 21 Apr 2008, 22:10:46
From tests I've made, there is/can be large delays between clients executing scripts, up to around 1-3 seconds at times, perhaps by the time your wait is starting, the other client has finished.
Title: Re: publicVariable thoughts...
Post by: L!nk on 23 Apr 2008, 18:43:52
Nope, not the problem.

I tested this by running three scripts after each other. The first script's result was perfect but the next two did not show the ruin but move the final building to the right location after the delay of each scripts.

It must have something to do with the scripts over-running each other.

When I run the script and wait till the delay is over, and run it again, it works fine.
 ???

L!nk