Jump to content
Sign in to follow this  
Fuzzy Bandit

Creating a Game Logic using Script

Recommended Posts

Hello!

Looking into how I would go about creating a Game Logic using script. I need a game logic to hold some variables so that JIP players get the updated variables, and the game logic must be created dynamically.

At the moment I'm trying to use:

(This script is currently called using nul0 = [1, "Neutral"] execVM "script.sqf";)

_tflagname = call compile format ["tflag%1", (_this select 0)];

_center = createCenter sideLogic;
_group = createGroup _center;
_logic = _group createUnit ["LOGIC", position this, [], 0, "NONE"];
_logic setVehicleInit (_tflagname + " = " + (_this select 1));

However, I'm getting the following error:

Error, 0 elements provided, 3 expected.

Also, if I did create it successfully using that code, would the variable be created successfully as well? If not, why not? Would I need to processInitCommands?

Cheers!

Share this post


Link to post
Share on other sites

I have no direct help for your question, but I am curious why you need to create the logic to hold the variables?

Would it not be easier to start the mission with a named GL and use an array assigned to that GL as a variable? For instance, in your example, you are creating "tflags". You could create an array variable to keep track of the tflags. Each element of the tflagArray could be a subarray of the different things you need to keep track of: location, size, neutrality.

You could dynamically set the elements of the array, rather than trying to create a new GL each time.

Sorry if you'd rather not even consider this. :) And good luck with your question!

Share this post


Link to post
Share on other sites

I wasn't sure of how to add to an already-created GL, and the reason I need a GL to hold the variables is so that JIP players get the updated variables (they change actively throughout the game). If I initiated them in the init.sqf JIP players would see default versions of the variables, while players who joined when the game started would see the updated versions.

How exactly would I 'assign' an array to a GL?

I'd prefer, however, to simply add a line of code to an already-active GL, initiating a variable.

Edited by Fuzzy Bandit

Share this post


Link to post
Share on other sites

Regarding the error message, the position is invalid.

_logic = _group createUnit ["LOGIC", [color="Red"]position this[/color], [], 0, "NONE"];

would the variable be created successfully as well?

No. As

(_tflagname + " = " + (_this select 1))

results in: "US = Neutral"

(if the content of the variable _tflagname was "US"). Remove the call compile in the first line, then _tflagname holds the string "tflag1";

Would I need to processInitCommands?

Yes, for those who are connected at the time you set the vehicle init. jip-clients execute it automaticly when they connect (http://community.bistudio.com/wiki/setVehicleInit)

so that JIP players get the updated variables (they change actively throughout the game)

Variables that have been broadcasted at least once by publicVariable are synchronized on jip-clients automaticly to the last value sent.

If I initiated them in the init.sqf JIP players would see default versions of the variables

For jip-clients the init.sqf is run after the synchronization stuff happens, meaning that you overwrite the variables with the default values, after you've received them. Just define those variables only on the server and broadcast them at the beginning. And during the game you're already broadcasting them when the flags are captured (http://forums.bistudio.com/showthread.php?t=99191)

in the init.sqf


if(isServer) then {
[indent]tflag1 = "Neutral"; publicVariable "tflag1";
tflag2 = "Neutral"; publicVariable "tflag2";
tflag3 = "Neutral"; publicVariable "tflag3";[/indent]

};

Share this post


Link to post
Share on other sites

Fantastic answer. Putting things into play as we speak.

Question: You say the position is invalid, but everything I try seems to fail when trying to get the position of the object the script is called from. What code can I use to achieve that?

Share this post


Link to post
Share on other sites

It doesn't matter where the GL is on map, right?

What about [1,1,1] , [42,1337,0] or [0,47,11] then?

logic = _group createUnit ["LOGIC", [1,1,1], [], 0, "NONE"];

Share this post


Link to post
Share on other sites

Initialize them only on the server. In init.sqf:

if (isServer) then
{
  myGlobalNumber = 0;
  publicVariable "myGlobalNumber";
  myGlobalBoolean = false;
  publicVariable "myGlobalBoolean";
};

And every time you update those variables, publicVariable them again if you want them to be updated for everyone (including JIP players).

Share this post


Link to post
Share on other sites
It doesn't matter where the GL is on map, right?

What about [1,1,1] , [42,1337,0] or [0,47,11] then?

logic = _group createUnit ["LOGIC", [1,1,1], [], 0, "NONE"];

True, it doesn't matter at all where this Game Logic is placed, but say I wanted to create a marker or a unit, how would I get the position?

Share this post


Link to post
Share on other sites

Do as gal said and btw why not just create an invisible helipad. Any object can hold variables, doesnt need to be a GL.

Share this post


Link to post
Share on other sites

You can use a broadcasted setVariable over a logic placed within the editor.

setVariable can be stored over groups/units/objects... if broadcasted, they'll be automatically updated to the clients joining/ingame.

Game Logic: myLogic

From server or client (locality doesn't matters there since it's broadcasted):

myLogic setVariable ['content','hello',true];

JIP Init.

_var = '';
waitUntil {_var = myLogic getVariable 'content'; !isNil '_var'};
sleep 2;
hint _var;

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  

×