Jump to content
Sign in to follow this  
seannybgoode

help a brother out - need some clarification on arma 3 scripting

Recommended Posts

Hi everyone,

So I'm a java developer with a couple years of experience now. I'm just wrapping up an associates of computer science, and I'm thinking my next project is going to be on Arma 3. Hopefully java for arma 3 will be released with the beta, but I'm not holding my breath. Even if the Arma JVM lets me spawn threads, it will be loads more powerful than SQF.

But I digress, I'm not holding my breath for java anymore, so I've resigned myself to learning SQF and piecing together how everything works. I figure it won't hurt when java is finally released.

Anyway, I've been reading and watching tutorials, and I really just need to get a clear picture on what's happening before I sink my teeth in.

I'll start with what I do know before I pose my question:

I know that scripts can be assigned to objects and run when that object is accessed or run on game start or what have you.

I know that the locality of objects changes based on who's using them. So locality changes from server to client, and then back to server when a player gets in a vehicle, drives from A to B, and then gets out.

I know that init.sqf is run by both the server and the client at the briefing screen.

I know that there are JIP issues that need to be thought about for MP game types (which is what I want to work on).

So here's my question:

What's the life cycle of an Arma 3 mission? Mission starts, runs init.sqf, and then what? Does flow of control end up in some master loop until the mission is completed? Is there some unseen master loop, and player actions cause SQF scripts to be called?

Does init.sqf run the same code on both the client and the server?

How is locality handled? Can I call something that checks locality on an object?

How does JIP get handled? Is there a way that the server can detect a player join and force necessary synchronizations?

I've seen some stuff whereby we can call non-sqf libraries using callExtensions. Does the game create instances of these classes? Can I create a class in say, C++, and then maintain global variables in that class? Can I write code such that the C++ class could call sqf script?

Ideally I would like to see a developers guide, but most of the tutorials cover really basic programming stuff that I really don't want to sift through. I really want to work in code as much as possible and avoid the editor like the plague. I want to program for universal situations rather than a labour intensive setup process of tying the mission script to game objects and so on. Anyway, I hope somebody here can shed some light on my questions.

Share this post


Link to post
Share on other sites

Hi seannybgoode,

please make sure to post in the right forum section. ;)

Thread moved.

Share this post


Link to post
Share on other sites
Also, a list of sqf operators and data types would be awesome.

Always keep this page bookmarked: http://community.bistudio.com/wiki/Category:Scripting_Commands_ArmA2

As for data types - you don't need to declare them. A variable will take the data type from the type it is assigned to:

_var = player; // Not the data type is Object Player
_var = "test"; // Now the data type is a string

Data Types: http://community.bistudio.com/wiki/Data_Types

Operators: http://community.bistudio.com/wiki/Operators

---------- Post added at 08:41 AM ---------- Previous post was at 08:34 AM ----------

To this question: "Does init.sqf run the same code on both the client and the server? "

Yes, the init runs on both, but keywords like isServer, isDedicated etc. allow you to define, which parts of the code are for clients, servers or hosts. You can for example make an init which will #include 2 different init's depending on which machine the code currently runs on.

I don't have time to double-check this right now, cause I'm at work, but for example something like:

// init.sqf

if(isServer) then
{
#include "/server/init.sqf"
} else
{
#include "/client/init.sqf"
};

Share this post


Link to post
Share on other sites
Hi everyone,

So I'm a java developer with a couple years of experience now

is that reason why u cant use wiki ?

http://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3

http://community.bistudio.com/wiki/Multiplayer_scripting

http://community.bistudio.com/wiki/Locality_in_Multiplayer

http://community.bistudio.com/wiki/Code_Optimisation

http://community.bistudio.com/wiki/6thSense.eu:EG

So here's my question:

What's the life cycle of an Arma 3 mission? Mission starts, runs init.sqf, and then what? Does flow of control end up in some master loop until the mission is completed? Is there some unseen master loop, and player actions cause SQF scripts to be called?

Does init.sqf run the same code on both the client and the server?

How is locality handled? Can I call something that checks locality on an object?

How does JIP get handled? Is there a way that the server can detect a player join and force necessary synchronizations?

I've seen some stuff whereby we can call non-sqf libraries using callExtensions. Does the game create instances of these classes? Can I create a class in say, C++, and then maintain global variables in that class? Can I write code such that the C++ class could call sqf script?

Ideally I would like to see a developers guide, but most of the tutorials cover really basic programming stuff that I really don't want to sift through. I really want to work in code as much as possible and avoid the editor like the plague. I want to program for universal situations rather than a labour intensive setup process of tying the mission script to game objects and so on. Anyway, I hope somebody here can shed some light on my questions.

1. ..then nothing

2. ?? .......no comment

3. sure

4. all sync is done automatically befor init.sqf

5. haha... that was nice one..

6. re u searching on YouTube ?

u know what... i really like smart guys like u re...

Edited by LoonyWarrior

Share this post


Link to post
Share on other sites
is that reason why u cant use wiki ?

http://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3

http://community.bistudio.com/wiki/Multiplayer_scripting

http://community.bistudio.com/wiki/Locality_in_Multiplayer

http://community.bistudio.com/wiki/Code_Optimisation

http://community.bistudio.com/wiki/6thSense.eu:EG

1. ..then nothing

2. ?? .......no comment

3. sure

4. all sync is done automatically befor init.sqf

5. haha... that was nice one..

6. re u searching on YouTube ?

u know what... i really like smart guys like u re...

Only one smart guy here ^^.

Share this post


Link to post
Share on other sites

Honestly the best way to get into editing the scripts is to just look at others missions, the best missions to learn from are those life missions because they pack so much scripting into the mission file and basically do something that wasn't intended.

The big issue really is that there isn't a one stop shop when it comes to anything arma, 30% of it is on armaholic 20% of it is on the forums and wiki and the rest is just out there in random parts of the internet on forums with dead links and downloads that are all on mega uploads website(that no longer exists).

Share this post


Link to post
Share on other sites
I think we're all able to keep it polite and on-topic, correct? :)

Yes we are, sorry. :(

The questions that are asked are very much like the questions I have to ask.

The links that have been posted are very useful indeed and I thank you for that.

The main question I would like answered is do all missions/ total conversions start in the missions editor or are there "modding tools" which allow us to do total conversions based off the engine such as the half life 2 source engine? And do all compilation our selves?

Share this post


Link to post
Share on other sites
Only one smart guy here ^^.

re u sure that u saw when we was registered ?

he was registered in February... I was registered month ago... ?

and do u think that i had to ask for anything like that to be able write in SQF ?

i know that it wasnt nice from me... but honestly... HE DIDNT TRY and i simply have big problem with that...

he isnt asking for something specific... if he will run to concrete problem i will try to help him... but not like this....

he tells us that he is java programmer and then he ask for basic questions witch can be found already aswered on wiki ? ...seriously?

and then he talks about C++ and additional libraries and i shouldnt take it as joke..?

once again... i know that it wasnt nice... but i said that from position of somebody who is only 1 month here and never had to ask for something like that................... think about that.....

---------- Post added at 16:17 ---------- Previous post was at 16:04 ----------

Yes we are, sorry. :(

The questions that are asked are very much like the questions I have to ask.

The links that have been posted are very useful indeed and I thank you for that.

The main question I would like answered is do all missions/ total conversions start in the missions editor or are there "modding tools" which allow us to do total conversions based off the engine such as the half life 2 source engine? And do all compilation our selves?

u re welcome....

and question is what u imagine under the "compilation"...

...lets say that compilation can be done automatically or manualy...

if u execVM somescript... that script is automatically compiled... https://community.bistudio.com/wiki/execVM

but u can also compile code manualy.. with https://community.bistudio.com/wiki/compile or better https://community.bistudio.com/wiki/compileFinal

....this is done while mission runs... it have nothing to do with editor............

so.... your question is ?

Share this post


Link to post
Share on other sites
Only one smart guy here ^^.

LOL yeah I laughed at this post. Fail troll.

---------- Post added at 17:02 ---------- Previous post was at 17:00 ----------

re u sure that u saw when we was registered ?

he was registered in February... I was registered month ago... ?

and do u think that i had to ask for anything like that to be able write in SQF ?

i know that it wasnt nice from me... but honestly... HE DIDNT TRY and i simply have big problem with that...

he isnt asking for something specific... if he will run to concrete problem i will try to help him... but not like this....

he tells us that he is java programmer and then he ask for basic questions witch can be found already aswered on wiki ? ...seriously?

and then he talks about C++ and additional libraries and i shouldnt take it as joke..?

once again... i know that it wasnt nice... but i said that from position of somebody who is only 1 month here and never had to ask for something like that................... think about that.....

---------- Post added at 16:17 ---------- Previous post was at 16:04 ----------

u re welcome....

and question is what u imagine under the "compilation"...

...lets say that compilation can be done automatically or manualy...

if u execVM somescript... that script is automatically compiled... https://community.bistudio.com/wiki/execVM

but u can also compile code manualy.. with https://community.bistudio.com/wiki/compile or better https://community.bistudio.com/wiki/compileFinal

....this is done while mission runs... it have nothing to do with editor............

so.... your question is ?

First off Loony. I don't want your semi-literate "help". I don't need your "help". I'm looking for general explanations so that I can have a general understanding of the system. I don't need help with specific programming problems. I'm a programmer, I can solve those problems myself.

Second, your feedback is unwanted and unwelcome. Kindly piss off. This forum needs an SQF/Arma scripting overview thread anyway.

Shoe fly shoe.

---------- Post added at 17:09 ---------- Previous post was at 17:08 ----------

[/color]

Honestly the best way to get into editing the scripts is to just look at others missions, the best missions to learn from are those life missions because they pack so much scripting into the mission file and basically do something that wasn't intended.

The big issue really is that there isn't a one stop shop when it comes to anything arma, 30% of it is on armaholic 20% of it is on the forums and wiki and the rest is just out there in random parts of the internet on forums with dead links and downloads that are all on mega uploads website(that no longer exists).

[/color]Yeah that's the problem I'm having. The wiki is incomplete, and everything else seems to be scattered around. I would really like to see some diagrams (think iOS application state diagram), and I would love to see some basic explanations of the system here *for developers*, which doesn't seem to exist.

I'm the kind of guy who would document these kinds of things myself, but I really need to see some serious documentation so I know what the hell is actually going on, as opposed to some kind of general idea/confusion. Once I'm there, I will happily draw up diagrams and write a developers guide.

I'm really just looking for a 1 or 2 page explanation or overview of the system.

Edited by seannybgoode

Share this post


Link to post
Share on other sites

To hopefully get this back on topic... There are some conversion mods out there but it does not work the same as some other engine's like "source" etc... In arma you do not have as much access to the engine. Almost every thing is done with the API. So almost everything is done either mission/script based or Mod based.

For some good examples of conversion mods and how they are done here are some you can download and open up to see how it works.

http://dayzmod.com/

http://www.invasion-1944.com/download-i44/

http://www.cityliferpg.com/

Share this post


Link to post
Share on other sites
Always keep this page bookmarked: http://community.bistudio.com/wiki/Category:Scripting_Commands_ArmA2

As for data types - you don't need to declare them. A variable will take the data type from the type it is assigned to:

_var = player; // Not the data type is Object Player
_var = "test"; // Now the data type is a string

Data Types: http://community.bistudio.com/wiki/Data_Types

Operators: http://community.bistudio.com/wiki/Operators

---------- Post added at 08:41 AM ---------- Previous post was at 08:34 AM ----------

To this question: "Does init.sqf run the same code on both the client and the server? "

Yes, the init runs on both, but keywords like isServer, isDedicated etc. allow you to define, which parts of the code are for clients, servers or hosts. You can for example make an init which will #include 2 different init's depending on which machine the code currently runs on.

I don't have time to double-check this right now, cause I'm at work, but for example something like:

// init.sqf

if(isServer) then
{
#include "/server/init.sqf"
} else
{
#include "/client/init.sqf"
};

Thanks Tox. Much obliged on the operators link. Don't worry about specifics, a general idea of how to solve the problem is good enough. No need to verify your code exactly.

Share this post


Link to post
Share on other sites

I know that scripts can be assigned to objects and run when that object is accessed or run on game start or what have you.

I'm not sure what you mean by this. Do you mean the initialization line?

What's the life cycle of an Arma 3 mission? Mission starts, runs init.sqf, and then what? Does flow of control end up in some master loop until the mission is completed? Is there some unseen master loop, and player actions cause SQF scripts to be called?

1. Mission loaded

2. Initialization statements on objects run

3. init.sqf (unless its immediate scope contains an interrupt - sleep or waitUntil - in which case it is pushed to 5)

4. Briefing displayed

5. Threads created in init.sqf (via spawn or execVM)

Does init.sqf run the same code on both the client and the server?

Yes.

How is locality handled? Can I call something that checks locality on an object?

As others already said, local.

How does JIP get handled? Is there a way that the server can detect a player join and force necessary synchronizations?

JIP client follows the same logic as any normal client so it is up to you to decide if you need any special handling within your scripts (you can use time to check if the game is already in progress). To detect JIP, you can use onPlayerConnected. Just be aware that it gets triggered at the start of the mission for everybody (server included) as well.

I've seen some stuff whereby we can call non-sqf libraries using callExtensions. Does the game create instances of these classes? Can I create a class in say, C++, and then maintain global variables in that class? Can I write code such that the C++ class could call sqf script?

The implementation is pretty basic. You get callExtension that can send and receive strings, it is up to you to do the rest.

Share this post


Link to post
Share on other sites
I'm a programmer, I can solve those problems myself.

its really clever to say this on forum like this...

my reaction:

its good for You.. enjoy that..

:yay:

Share this post


Link to post
Share on other sites
I'm not sure what you mean by this. Do you mean the initialization line?

1. Mission loaded

2. Initialization statements on objects run

3. init.sqf (unless its immediate scope contains an interrupt - sleep or waitUntil - in which case it is pushed to 5)

4. Briefing displayed

5. Threads created in init.sqf (via spawn or execVM)

Yes.

As others already said, local.

JIP client follows the same logic as any normal client so it is up to you to decide if you need any special handling within your scripts (you can use time to check if the game is already in progress). To detect JIP, you can use onPlayerConnected. Just be aware that it gets triggered at the start of the mission for everybody (server included) as well.

The implementation is pretty basic. You get callExtension that can send and receive strings, it is up to you to do the rest.

Yes this is exactly what I was looking for! Thanks!

So let me just see if I'm understanding what's happening here:

After init.sqf, I can call execVM or spawn to spawn threads. These threads take an SQF script file and run them within their own thread.

Now I'm left with a couple more questions:

How do threads, or instances of sqf script, communicate with eachother?

Consider this java code where I create an instance of an object:

SomeObject thing = new SomeObject(); //I think of this as being sorta like calling execVM without going into java threading business

Now I want to communicate with this instance, say, set a state:

thing.setState(Thing.WAITING_STATE);

What would the sqf equivalent be to the above code?

Second, can I create an instance of something in memory without spawning a thread? Would this be the difference between spawn and execVM?

Or is it the case that only threads can be created, and that there are no instances per-se?

Third, if it is indeed the case that Threads can talk to each other, what kind of mechanisms exist for thread safety?

I know that SQF isn't an OO language, so comparing Java to SQF is kinda like comparing apples and oranges. I know there's a bit of a pitfall here in applying OO concepts to a language that isn't OO, but I'm not really sure how else to express these ideas. I don't have much experience with non-OO languages like JS, so there's a little bit of a disconnect there for me. I do have some limited python experience though, so I'm not totally unfamiliar with the dynamic typing.

Share this post


Link to post
Share on other sites

They can't communicate. The only two ways to get data in or out is to pass data to the thread:

_null =[this,stuff gets passed to the thread] execVM "my script.sqf";

And saving variables to a global namespace and then checking those in another thread. Scope matters a lot when coding like this.

---------- Post added at 03:16 PM ---------- Previous post was at 03:10 PM ----------

A lot of scripting in arma revolves around functions. You pass data to them and either wait for a return or they go off on their own to do a task while your other script finishes up.

Share this post


Link to post
Share on other sites

So let me just see if I'm understanding what's happening here:

After init.sqf, I can call execVM or spawn to spawn threads. These threads take an SQF script file and run them within their own thread.

You can do that inside of init.sqf but they won't run until you get past the briefing (which you may or may not want, could be a problem with creating markers or objectives for instance)

How do threads, or instances of sqf script, communicate with eachother?

Consider this java code where I create an instance of an object:

SomeObject thing = new SomeObject(); //I think of this as being sorta like calling execVM without going into java threading business

Now I want to communicate with this instance, say, set a state:

thing.setState(Thing.WAITING_STATE);

What would the sqf equivalent be to the above code?

You'd use a global variable.

Second, can I create an instance of something in memory without spawning a thread? Would this be the difference between spawn and execVM?

Or is it the case that only threads can be created, and that there are no instances per-se?

You can only create threads or use ones provided by the game (such as in case of event handlers).

Third, if it is indeed the case that Threads can talk to each other, what kind of mechanisms exist for thread safety?

There isn't one. SQF "threads" are not actually proper threads. Everything in SQF runs synchronously.

Share this post


Link to post
Share on other sites
You can do that inside of init.sqf but they won't run until you get past the briefing (which you may or may not want, could be a problem with creating markers or objectives for instance)

You'd use a global variable.

You can only create threads or use ones provided by the game (such as in case of event handlers).

There isn't one. SQF "threads" are not actually proper threads. Everything in SQF runs synchronously.

Well I can't give SQF any points for best practices. I can already see that using the global namespace for anything that needs to be shared between threads as problematic. I'm sure that it gets confusing with large missions, and it's probably actually a big source of the problem when it comes to the Arma 3 security issues, since anything that needs to be shared must be visible to everything else.

Anyway, this is good so far. Just a couple more questions.

I know that variables can be private, public, or they can be public and we can broadcast over the network to all the clients connected. I forget what it's called at the moment.

Now my question is can functions be public or private?

Share this post


Link to post
Share on other sites

Now my question is can functions be public or private?

You can limit the scope of functions by only running them on a particular machine, for instance the server, or only on clients or on one particular client.

Share this post


Link to post
Share on other sites
You can limit the scope of functions by only running them on a particular machine, for instance the server, or only on clients or on one particular client.

I'm not sure what you mean. Like this?

if(isClient)
{
  run script
}
else
{
 return ;
}

Share this post


Link to post
Share on other sites

if(isClient)
{
  run script
  // My client functions/scripts....stuff etc.
  myfunction = do some stuff...
}
else
{
// What ever we ran above would not be availibel in this case unless we sent the data to this scope, like we talked about before.
// You can do stuff here for what ever is not a client... ie the server.
}

If you create the function on only one machine then only it will know about it. If you create it on everyone's machine you can execute it everywhere.

Edited by Riouken

Share this post


Link to post
Share on other sites
if(isClient)
{
  run script
  // My client functions/scripts....stuff etc.
  myfunction = do some stuff...
}
else
{
// What ever we ran above would not be availibel in this case unless we sent the data to this scope, like we talked about before.
// You can do stuff here for what ever is not a client... ie the server.
}

If you create the function on only one machine then only it will know about it. If you create it on everyone's machine you can execute it everywhere.

That seems like a really wacky way to define scope. And it's not really what I'm talking about. Lets just consider one machine for these purposes. Is there a way to create an instance of something, and then call the member functions of that instance?

Like what if I have a set of functions that I would like to use over and over, can they be called from anywhere regardless of scope? Can they only be called locally? If neither of those cases, how do we define the scope?

Can you demonstrate some simple function calls, and some function definitions, like calling a function and returning a value?

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  

×