Jump to content
Sign in to follow this  
Luna Starr

Create custom states for script reference

Recommended Posts

Hello there,

 

I need to have 5 'states' for my current mission, these states will be referenced by scripts throughout the mission, they won't be in order and can change at any time, how does one set up 5 new states that the editor will recognise in my scripts.

Basic states for reference to mission objectives and current condition numbering 1-5.

 

For instance I have a certain weapon and if a certain mission was done, the condition would be 4, I can then use these conditions throughout the mission.

 

Help will be appreciated.

Share this post


Link to post
Share on other sites

Not sure if that's what you need, giving a less abstract example would definitely help here.

Try something like an array, holding boolean values:

TAG_fnc_myStates = [false,false,false,false,false];

//changing states:
TAG_fnc_myStates set [2,true];

//results in [false,false,true,false,false]

//to check for a state would be
TAG_fnc_myStates#2 // would be true

Alternatively you could look into BIS_fnc_bitflagsCheck for more complex states.

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

Thanks, so shall I put that into my init.sqf as it will be used throughout my mission?

 

Thanks for that, I now understand how to make my own states, much appreciated. Just to confirm, I put the top line into the ini.sqf.  

 

Just out of curiosity why did you use 'TAG_fnc_myStates' as I just found out I can just put '_state1 = false' and that works too?

 

Thanks again :)

Share this post


Link to post
Share on other sites

Ok, another question and it's kind of related..

 

So in my mission I require the player to have different states, I would like each state to have a name, I tried creating an array for this but it never works..

 

_uniform = ["hostile","unfriendly","friendly1","friendly2","friendly3","friendly4"];
_uniform select 0;

I thought this would set 6 different states and select the first.

 

To check what state the player is in I had this code to find out what state they were in..

 

if (_uniform=="unfriendly") then {

This never works,  what am I doing wrong here?

 

 

Share this post


Link to post
Share on other sites

you need to save the "select 0" in a new variable or use it directly inside the condition. like

 

_state = _uniform select 0;

 

and then either do

if (_state == "unfriendly") then
{
	///amazing things
};

or

if (_uniform select 0 == "unfriendly") then
{
	///amazing things
};

you're still beign abstract though, so hard to tell where this is going. i get an idea from your strings but it would be interesting how your system is supposed to work. so far it looks like you set a state for each player at missions start and act accordingly? it would also be important to know if the condition is checked in another script. because local variables will be a problem then. again depedning on what the goal is you might want to look into

https://community.bistudio.com/wiki/setVariable

and

https://community.bistudio.com/wiki/getVariable

 

although this might be not needed for SP since a global variable would be enough, this will definately be good to know.

 

to make it global simply get rid of the _ infront and make sure to use a name that has a low probability of colliding with other people's code.

a common method is using a tag infront taht represents your name or the mod you are working on. so from what i can tell so far it would probably make sense to make the _uniform variable global like this LS_uniform so you can access it in your condition in another script.

 

  • Like 1

Share this post


Link to post
Share on other sites
13 hours ago, Luna Starr said:

Just out of curiosity why did you use 'TAG_fnc_myStates' as I just found out I can just put '_state1 = false' and that works too?

 

As @bad benson described, tagging your script functions is best practice. The "TAG" is a placeholder for your personal tag, which is typically a 3-4 letter contraction of your handle. Mine is HARZ. You could use LUN/LUNA/LST/LUST/etc. Or whatever else you wanted to use, really. It's just a way to identify your functions and mitigate code collisions.

  • Like 2

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  

×