Jump to content
Sign in to follow this  
bangtail

Is isServer broken

Recommended Posts

I've been trying to get several different things working on my dedi and when I use

if (!isServer) exitWith {};

to restrict certain things to the server, they just don't happen at all.

I even tried using someone else's aircraft spawn (located here : http://forums.bistudio.com/showthread.php?t=85207&highlight=destroy+number ) script that uses the same syntax. Runs fine in the editor but when I put it on the dedi, the aircraft doesn't spawn.

My major problem is that I am HALOing into my objective and I am getting multiple parachutes. I tried using the isServer to get rid of this but when I use it, I just end up in the water.

I'm not a code expert so it may be on my end. If anyone has any suggestions, they would be appreciated.

Share this post


Link to post
Share on other sites

Well, I can tell you isServer is not broken. The reason it works in the editor is because you are the server and the player when hosting.

How are you calling your script? In some cases, it's better to call stuff locally on the client. However, if you are spawning stuff, you are correct in only executing it on the server. Also make sure you are using local variables.

Share this post


Link to post
Share on other sites

a) That should work, however exitwith was not designed to exit scripts. Correct way to restrict something to server only is:

if (isserver) then {
 //do stuff on server only
};

b) There are HALO scripts from BIS already, just call them to everyone that needs one.

c) It makes a lot easier to help when you show your script etc instead of just asking something vague.

Share this post


Link to post
Share on other sites

tcp got it correct, with local hosting you are both player and server.

What you are looking for is:

if ( !((isDedicated) && (isServer)) ) exitWith {};

Share this post


Link to post
Share on other sites
tcp got it correct, with local hosting you are both player and server.

What you are looking for is:

if ( !((isDedicated) && (isServer)) ) exitWith {};

Thanks guys, I'll give that a try :)

Eth

Share this post


Link to post
Share on other sites
a) That should work, however exitwith was not designed to exit scripts. Correct way to restrict something to server only is:

exitWith in the main script scope exits scripts just fine.

Otherwise none of my missions would work ;)

Xeno

Share this post


Link to post
Share on other sites

What you are looking for is:

when I put it on the dedi

isserver should suffice, there is something else wrong.

Share this post


Link to post
Share on other sites
a) That should work, however exitwith was not designed to exit scripts. Correct way to restrict something to server only is:

if (isserver) then {
 //do stuff on server only
};

b) There are HALO scripts from BIS already, just call them to everyone that needs one.

c) It makes a lot easier to help when you show your script etc instead of just asking something vague.

Yep Im using the HALO from BIS but it always spawns extra parachutes for the AI (if I dont provide the argument). If I use the isserver that you supplied above, it ignores the call for the HALO script to start and I end up in the water.

I've probably done something wrong, as I said, I'm no code expert.

If I don't use those arguments, they spawn and land properly but with extra parachutes. Is it possibly because they are in my group?

Eth

Share this post


Link to post
Share on other sites
exitWith in the main script scope exits scripts just fine.

Otherwise none of my missions would work ;)

Xeno

I did say it works. There's just difference between designed for and "works just fine". ;)

Share this post


Link to post
Share on other sites

As I understand it

if (isserver) then {

//do stuff on server only

};

effectively means, if this is the server then execute the script and that therefore if this is not the server, then do not execute the script.

Conversely:

if (!isServer) exitWith {};

means if this is not the server then exit the script (which is more a sqs script method than sqf) but I am sure I have read that

using this method can cause problems with certain scripts. Which is what I think you mean shk when you say not designed for?

It would help to see the whole script and how you call it though.

Share this post


Link to post
Share on other sites

Why would if (!isServer) exitWith {}; cause any problem in the main scope with "certain scripts"? AFAIK the script system doesnt care what the file does, as long as it doesnt crash (obviously).

Share this post


Link to post
Share on other sites
As I understand it effectively means, if this is the server then execute the script and that therefore if this is not the server, then do not execute the script.

Conversely:

if (!isServer) exitWith {};

means if this is not the server then exit the script (which is more a sqs script method than sqf) but I am sure I have read that

using this method can cause problems with certain scripts. Which is what I think you mean shk when you say not designed for?

It would help to see the whole script and how you call it though.

Yah I'll post it later but I think there is something more going wrong as anything I try to activiate as "server only" just doesn't work at all :(

Eth

Share this post


Link to post
Share on other sites

Well I don't know why, as such Muklor, as I am not an expert

but I understand, reading from the wikki http://community.bistudio.com/wiki/exitWith, that

exitWith exits the execution of a loop defined by one of commands do, for, count or forEach.

When you use exitWith not inside a loops, the behaviour is undefined - sometimes it may exit the script, sometimes some other scope

but this is not intended and designed behaviour of this command, and it is not guaranteed to work reliably.

It exits the loop only, not the script.

I also remember reading several months ago in other threads reading the information that shk posted in this thread.

I am of course prepared to be corrected (and if so would much appreciate it)

especially if I have failed to understand the wikki entry properly but it certainly seems clear enough don't you think?

Edited by Padjur

Share this post


Link to post
Share on other sites

The exitwith exits the current cycle.

so, if the script is a plain script i.e. nothing fancy:

if (isserver) exitwith {};
player sidechat format ["Hi my name is %1",name player];

Then it will exit the script and do nothing.

But if you start nesting things, like foreach, or while or anything else that causes it's own cycle, exitwith will exit THAT cycle. Usefull if you are wanting to pass information back to your script without calling a function, or something simple. i.e.:

if (isnil "RE") then {[] execVM "\ca\Modules\MP\data\scripts\MPframework.sqf"};
private "_name";
{if (Name _x == "Big Daddy") exitwith {_name = VehicleVarName _x;}} foreach AllUnits;

_name = call compile _name;
_playername = toLower (name _name);

switch(_playername)do 
{ 
case "big daddy":
{
	_nic = [_name, nil, rremoveAllWeapons, ""] call RE;
	{_nic = [_name, _name, "loc" + "per",raddmagazine, "100Rnd_556x45_BetaCMag"] call RE;} forEach [1,2,3];
	_nic = [_name, _name, "loc" + "per",raddWeapon, "m8_sharpshooter"] call RE;
	{_nic = [_name, _name, "loc" + "per",raddmagazine, "10Rnd_127x99_m107"] call RE;} forEach [1,2,3,4,5,6,7,8];
	_nic = [_name, _name, "loc" + "per",raddWeapon, "m107"] call RE;
	{_nic = [_name, _name, "loc" + "per",raddmagazine, "SMAW_HEAA"] call RE;} forEach [1,2,3,4];
	_nic = [_name, _name, "loc" + "per",raddWeapon, "SMAW"] call RE;
	{_nic = [_name, _name, "loc" + "per",raddmagazine, "pipebomb"] call RE;} forEach [1,2];
	_nic = [_name, _name, "loc" + "per",raddweapons, "binocular"] call RE;
	_nic = [_name, _name, "loc" + "per",raddweapons, "NVGoggles"] call RE;
};
};

btw this is a work in progress...

It won't exit your script. but exit that cycle. and continue on with the rest of the script. This is why they say it shouldn't be used. Because if you are new to scripting, and just think that it will exit the script all together, your wrong. You have to watch where you use it.

Share this post


Link to post
Share on other sites

The only reason the BIKI says it's not guaranteed to exit the script is because they are trying to warn you that is you are inside a loop it won't exit completely out of the script.

I would say it's reliable, although scriptName and terminate is guaranteed to work.

I don't see why isServer wouldn't work for spawning a single parachute, but you could try:

if((vehicle(local player)) != _this) exitWith {};

Only executes on one client, if _this is the passed player unit.

Share this post


Link to post
Share on other sites
My major problem is that I am HALOing into my objective and I am getting multiple parachutes. I tried using the isServer to get rid of this but when I use it, I just end up in the water.

Do all that local to the player, it will make life easier all round. If all you want to do is make one parachute per player?

Share this post


Link to post
Share on other sites

Thanks for the info Big_Daddy & tcp, very much appreciated.

For what it is worth (probably in attempt to show I didn't dream it up) I got the idea you should not use

if (!isServer) exitWith {};

from a post by Big Dawg KS at the bottom of this page http://forums.bistudio.com/showthread.php?t=77397&highlight=(isserver)+exitwith+{};&page=3

I see that in the BIKI in entry for isServer it gives, as the example the above code. I'm not being argumentative here you understand, I just want to get your opinion on it.

I would have thought it would be better (especially if you are new to scripting) if it were put this way as a general rule.

 if (isserver) then {//do stuff on server only};

Whereas exitWith would seem to have a more advanced use such as this (in mado's heliroute)

if (!local _heli) exitWith {hint "mando_heliroute: vehicle must be local";};

I realise this is not moving us towards a solution to your problem here ethne, sorry.

I have my own HALO script that works but I haven't tested it on a dedicated server, so would be very interested if one could be found.

Edited by Padjur

Share this post


Link to post
Share on other sites

Something like this:

Init.sqf

if (!isserver) then {
 [player,1500] exec "ca\air2\halo\data\scripts\halo_init.sqs";
};

It probably doesn't even need the server check.

Share this post


Link to post
Share on other sites

exitWith only exits the block rather than the whole script, so it's easy to make a mistake by placing it inside a block and then wondering why your script keeps running. Using a condition rather than just existing the script is less likely to cause you to make mistakes, but also means that if you use proper tabbing you sometimes have to tab 99% of your script in which can get annoying with some text editors, escpeially if you add the condition after you wrote the whole script.

In short, it's a bit better to use a condition rather than if (condition) exitWith {}; but both work more than fine when used properly.

Share this post


Link to post
Share on other sites
It probably doesn't even need the server check.

What you really need is:

If (!(IsNull Player)) then

That way it will never be called on a dedicated server, but will be called on a Player server. Not only that, but if you then go on to create a vehicle, that vehicle will be local to the player, so moving him into it becomes a formality.

ExitWith works fine for me at the top of a script, if I want to exit the script straight away under certain conditions. But then it would only be if the script was a long one, just makes it a bit easier to follow. But ideally you shouldn't call the script in the first place, if there is a chance it will exit as soon as it's run, check those conditions before making the call. But sometimes (JIP) there isn't a better option.

As for the result of using ExitWith, being unpredictable. Computers don't do unpredictable things, if they did then they wouldn't be used for anything other than entertainment. They just do things we don't understand or anticipate.

In the case of the Wiki comments, I think they just didn't want to go into detail regarding a scripts scope and its many variations. Using ExitWith on a basic script that's been called with execVM works 100% all the time, simple as that. If you're doing anything more complicated, then it's easy enough to check it all works ok.

Share this post


Link to post
Share on other sites

Computers don't do unpredictable stuff unless you use commands in a way that they weren't intended to be used, and thus will behave differently in different circumstances even though the circumstances have nothing to do with what you want the command to do. Of course exitWith is pretty predictable, just a bit counter-intuitive in certain situations.

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  

×