Jump to content
Sign in to follow this  
liebstpanzer

sqf programming beginner

Recommended Posts

Hi guys, I'm new to the community but not necessarily to ArmA. I used to mod the source engine and really used Garrys mod to do so, so my experience is mainly lua or GLua and I can read C++.

Now I've already visited the wiki and I'm on the introduction page for scripting. I'm really here to introduce myself because i'm sure I'll have a lot of questions.

If you read this thread, thankyou and if you reply, please help me out. Are there any articles you would suggest? Do you have any tips and would you like to discuss with me the limitations(what I can and cannot do.), benefits of learning this language, what tools to use(I'll be studying at work since sometimes I have free time to do so.) and what I can expect while working with this engine?

One last thing, I'm really interesting in modding ontop of DayZ(i'm positive we've all heard of this mod) so if you can please let me know if it'd be possible to make code that is stand-alone AND can work WITH DayZ and what ever variables or globals it might use.

Thank you.:yay:

Share this post


Link to post
Share on other sites
Guest

I suggest you ask DayZ specific scripting questions on the DayZ forums, not here cause that will have your thread locked. (see forum rule &8)

For scripting questions about the default game you can continue using this current thread.

I have also moved your thread to the correct forum section, please take a minute to try and post in the correct forum section!

Share this post


Link to post
Share on other sites

Getting in SQF coding has steep learning curve. At first it is all alien, then suddenly after awhile everything starts making sense. I suggest you learn from example, look into simple scripts and reference wiki for specific commands.

Share this post


Link to post
Share on other sites
I suggest you ask DayZ specific scripting questions on the DayZ forums, not here cause that will have your thread locked. (see forum rule &8)

For scripting questions about the default game you can continue using this current thread.

I have also moved your thread to the correct forum section, please take a minute to try and post in the correct forum section!

Well my question do pertain to the engine itself and not really what version of the game it is.. Are there local and global variables. In lua there are we would define a global:

Var = 1;

Now that Var is defined(lua is also very case sensitive) I am able to access Var throughout my mod or from two separate script files.

local Var = 1;

local Var is only accessible through that one script file. Do we have this type of ability in sqf?

Getting in SQF coding has steep learning curve. At first it is all alien, then suddenly after awhile everything starts making sense. I suggest you learn from example, look into simple scripts and reference wiki for specific commands.

Thankyou, I was going to ask for notepad ++ syntax but you took care of that just by posting. :239:

Share this post


Link to post
Share on other sites
Guest

I am talking about DayZ specific scripting.

When you want to make things for DayZ you will have to keep in mind the mod changes many things compared to the default game. So, once you want to build a script for DayZ you can not rely on normal scripting as the mod may change its behaviour, that is the reason why DayZ script making questions do belong on the DayZ forums and not here.

When you have more questions about it contact me over PM, for scripts you wish to make for the default game you can continue using this thread.

Share this post


Link to post
Share on other sites

I would suggest not to start scripting with DayZ in mind. DayZ is pretty complex for a beginner to get used to the engine and requires at least some basic understanding about stuff like eventhandlers, functions, scopes and variables. It tends to be rather messy for a beginner to get the idea of what is going on and I can remember lots of evenings where I sat in my room thinking "how the fuck is this supposed to work" and not making any progress for hours^^. This is how I learned it and still learn:

1: This is the most important reference for all your needs and it nearly answers all your quetions, at least if you know where to search for the answer. The Community Modding Bible

2: BIKI, you can find the links to the BIKI in the link above but I assume you found it already. The BIKI features not only all the syntax with examples and detailed explanations contributed by the community and devs, it also features tons of tutorials for beginners and even advanced stuff like in depth code optimizing. You will not only find information about scripting but also config references and asset creation tutorials.

3: Learn from others. When you have a specific problem the easiest way is to search for people that made something simillar and have a look at how they solved the problem. This is no call for plagiarism but for inspiration. Getting started is the biggest problem as a beginner and this may help you with your first babysteps. And in the end you dont have to invent the wheel completly new every time. Just ensure to ask for permissions in case you want to use somebodys code or asset in your creation, dont take credits for other peoples work.

4: Ask the community. Use the forums, not only this but OPFEC, armaholic or clan forums. Get in contact with other modders. Everybody I asked about a problem I had was really helpfull. Its a great community.

Share this post


Link to post
Share on other sites

Pretty much everything you need is there in the CMB. You'll find this forum to be extremely helpful as well. Coming from a point of TOTAL ignorance about a year ago, I can now do some pretty neat stuff, so I'm sure you'll have no problems getting into it.

To answer a specific question, local variables are indeed possible. They are affixed with an underscore:

_local = 0;

global = 1;

They can be local to a script, or scoped to specific portions of a script.

Also, take Foxhound at his word!

Share this post


Link to post
Share on other sites

to answer you question

_local = 1;

Global = 1;

public = 1; Publicvariable "public";

Edited by Mikie boy

Share this post


Link to post
Share on other sites

Actually it is more like

private - _var

public local - var

public global - publicVariable "var"

Share this post


Link to post
Share on other sites

Hi guys, thank you for the replies. I've been trying to take the past week and a half to read up on the wiki and I am kind of disappointed with what I've found. I mean there are a lot of good articles and things to read and I'd love to jump into the scripting but I'm a little confused as to a few things:

I bought ArmA2 and ArmA2:OA through steam so the file structure is just a little different but I'm confused with it.

I don't really understand functions could someone give me an example of a function(just explain a little about the structure and calling it) Can you pass arguments through a function? <- to explain this.. in Lua the way we would setup and call a function would be like so:

function _ExampleFunc(arg1, arg2)
local Param = arg1 .. arg2;
print(Param);
end
_ExampleFunc("Print", "this.");
--returns 'Print this.'

Lastly, after I figure out the file structure play with some variables and such I'd like to start my first project. I'd love to make a script which would speed up the time of day slightly but slow down or speed up depending on the time in-game. Now I don't want to steal anyones work so if you guys can point me in the right direction(show me some utility functions or commands which actually change the time of day, some dos and don'ts when it comes to what ever I might face and just really explain the syntax I should be using).

Thank you for whom ever might read this, I'd really appreciate it. :404:

Edited by liebstpanzer

Share this post


Link to post
Share on other sites

And what exactly has Arma 3 to do with his scripting questions? Not everyone is interested in using an early Alpha version of a game when a stable one does the same. ;)

Share this post


Link to post
Share on other sites
And what exactly has Arma 3 to do with his scripting questions? Not everyone is interested in using an early Alpha version of a game when a stable one does the same. ;)

I agree and also I'm in a budget for the next few months so I cannot afford it. Another thing is, is that I hope that within the next few months, after I upgrade my PC and purchase ArmA3, that more documentation about scripting would have been written, bugs fixed and what ever.

Share this post


Link to post
Share on other sites
And what exactly has Arma 3 to do with his scripting questions? Not everyone is interested in using an early Alpha version of a game when a stable one does the same. ;)

I'll explain. It has a nice debug console and plenty of reference material under your fingertip, right when you need it. If you are learning this is what you should be starting with to avoid the pain of arma coding. However I sense you are not very pleased with my advice, so here, I'm deleting it.

Share this post


Link to post
Share on other sites
I'll explain. It has a nice debug console and plenty of reference material under your fingertip, right when you need it. If you are learning this is what you should be starting with to avoid the pain of arma coding. However I sense you are not very pleased with my advice, so here, I'm deleting it.

no please dont, I appreciate your advice. I really do and your new post really explains why I should start with ArmA3. The thing is... is that I dont want to wait until I am in a financial position to purchase ArmA3(school and insurance is really killing me) but I respect your opinion killzone so I think I might wait until ArmA3 if thats what you really suggest. I'll wait until then before I bump this thread and repost my questions then I guess.

Share this post


Link to post
Share on other sites
I don't really understand functions could someone give me an example of a function(just explain a little about the structure and calling it) Can you pass arguments through a function?

basic concept

hinting = {
	 _firstWordToHint = _this select 0;
	 _secondWordToHint = _this select 1; 
                _combined = _firstWordToHint  + _secondWordToHint;
	 hint _firstWordToHint;
	 sleep 2;
	 hint _secondWordToHint;
                sleep 2;
                hint _combined;

    };


["Print"," this"] spawn hinting; 

Share this post


Link to post
Share on other sites
basic concept

hinting = {
	 _firstWordToHint = _this select 0;
	 _secondWordToHint = _this select 1; 
                _combined = _firstWordToHint  + _secondWordToHint;

	 hint _firstWordToHint;
	 sleep 2;
	 hint _secondWordToHint;
                sleep 2;
                hint _combined;

    };


["Print"," this"] spawn hinting; 

I'm still not sure how to save scripts in SQF format or activate them in ArmA2. Am I doing this right?:

_LocalArray = ["So", "this", "is", "S", "Q", "F", "programming", "huh?", "Not", "bad!"] -- is this setup correctly
HintingPartTwo = {

for[ {_val = 1}, {_val <= 10}, {_val = _val + 1}] do {

	_SelectedWord = _LocalArray select _val; -- does this work
	_num = random 5 + _val + _this select 0; --would _this select 0 be "argument"

	hint _SelectedWord + [" we add this num for fun! --"] + _num; -- would this be the right way to add a string to this correctly?
	sleep _val + 1;

};

};


["argument"] call HintingPartTwo;-- am I doing it right

---------- Post added at 13:51 ---------- Previous post was at 13:47 ----------

I left some notes in the code above so for who ever replies please respond to them as well.

Edited by liebstpanzer

Share this post


Link to post
Share on other sites
I'm still not sure how to save scripts in SQF format or activate them in ArmA2. Am I doing this right?:

Scripting Tutotial - http://www.armaholic.com/page.php?id...highlight=FOCK

worth a look - would be in your interest to see how you execute files, and general basics.

_LocalArray = ["So", "this", "is", "S", "Q", "F", "programming", "huh?", "Not", "bad!"];

HintingPartTwo = {

for[ {_val = 1}, {_val <= 10}, {_val = _val + 1}] do 
{

	_SelectedWord = _LocalArray select _val; //yes
	_num = random 5 + _val + _this select 0; --would _this select 0 be "argument" - //yes but it cant be a string!!!!  + careful with order of precedence

	//incorrect 
	hint _SelectedWord + " we add this num for fun! --" + _num; //incorrect = will only hint _selectedword

	//try
	_newhint = _SelectedWord + " we add this num for fun! --" + _num;
	hint _newhint;

	sleep _val + 1;

};

};

//
_value = 6;	   
[_value] call HintingPartTwo;-- am I doing it right

Share this post


Link to post
Share on other sites
publicvariable Array = [1, 2, 3]; --Is this correct use of publicvariable?


I.E. 
func = {
	_loc = _this select 0 or 1 -- okay assuming the above is correct how can I turn _this into a string. 
	hint _loc; -- then
	sleep _loc -- can we turn it back into a number??
}
Array call func -- is Array able to be used this way?

Share this post


Link to post
Share on other sites
publicvariable Array = [1, 2, 3]; --Is this correct use of publicvariable?


I.E. 
func = {
	_loc = _this select 0 or 1 -- okay assuming the above is correct how can I turn _this into a string. 
	hint _loc; -- then
	sleep _loc -- can we turn it back into a number??
}
[Array] call func -- is Array able to be used this way?

Edited by liebstpanzer

Share this post


Link to post
Share on other sites

You code looks alot like C++

The Arma language is based on C++ but relies on a lot of predefined constants so some syntax is different..

Best to get familiar with another game besides DayZ. Learn what it does before looking at the scripts. Then crack it open and start looking up the commands.

I think Domination may have used a lot of code closer to C++

Very strange coding in Domination.

There are Tons of very good scripters in here and lots of people willing to help if you have a half decent or challenging question.


func = {
       _loc = ["5","string_b"];
	_locb = _this select 1
	if ((count _loc) > 0 and _locb != "") then
	{
		hint "no string found";
	};
	sleep _loc this select 0;
               publicVariable "_loc";
};
call func;

Me thinks..

Also Check out this time script although its not sqf but fsm.

http://forums.bistudio.com/showthread.php?137061-MP-Fast-time-FSM-JIP-Compatible

Edited by Jigsor

Share this post


Link to post
Share on other sites
You code looks alot like C++

The Arma language is based on C++ but relies on a lot of predefined constants so some syntax is different..

Best to get familiar with another game besides DayZ. Learn what it does before looking at the scripts. Then crack it open and start looking up the commands.

I think Domination may have used a lot of code closer to C++

Very strange coding in Domination.

There are Tons of very good scripters in here and lots of people willing to help if you have a half decent or challenging question.


func = {
       _loc = ["5","string_b"];
	_locb = _this select 1
	if ((count _loc) > 0 and _locb != "") then
	{
		hint "no string found";
	};
	sleep _loc this select 0;
               publicVariable "_loc";
};
call func;

Me thinks..

Also Check out this time script although its not sqf but fsm.

http://forums.bistudio.com/showthread.php?137061-MP-Fast-time-FSM-JIP-Compatible

okay, thanks. I'll be sure to check that out later once I get home from work. I still haven't been able to get a quick answer on how files are saved and accessed so I've pretty much been reading and studying syntax blindly...

Anyways I've been trying to understand the syntax so if you could guys, please, review this code:

_LocalArray = [
["Sup" = [", so"]],
["wats going on?" = ["Not much dog , chillin'"]]
];

HintingPartFour = {

_Loc = _this select 0;
_Num = _this select 1;

{
	_SelectedWord set [count _SelectedWord + 1, _x select _Num];
	hint _SelectedWord; -- this should hint " , so" && "Not much dog, chillin'" how can we print "Sup" && "wats going on?"

} foreach _Loc;

};

//
for {_val = 1}, {_val <=2}, {_val = _val} + 1 do { 

[_LocalArray, _val] call HintingPartFour;-- am I doing it right, sir? I haven't tested any of this yet....

};

My question now is... Is my foreach correct. Am I still calling this function correctly... is _x being used correctly and will _SelectedWord hint as well? If that's all correct, cool.

I also have another question, am I able to list or select my Array keys and not just the value?

In Lua tables are the same thing as an array for the most part. They were setup quite similar:

local table = {};
table = {1, 2, 3} 
table = nil;
table = {1 = 1, 2 = {}};

we could access the specific table item like this: table[1] would return 1. table[2] would return {};

We would also be able to index tables with a string:

table = { ["String"] = 1, ["string"] = 2 };

table["String"] returns 1
table["string"] returns 2 -- I just wanted to show Lua is also case sensative.

Now what I would want to try to do above would be like this(I'm writing it in lua to try and clarify my point for lack of a better method in SQF):

local tab = {}
tab["Sup"] = ", so";
tab["wats going on?"] = " Not much dog, chillin'";
for key, value in pairs(tab) do
print(key..value); -- key == Sup wats going on? value == , so && Not much dog, chillin'
end

(This ruins our ability to keep things listed in numerical order so what you could also do with lua is this below...):

tab[1] = {THIS = "string", THAT = 123};

we would access THIS && THAT like so:

tab[1].THIS returns "string"

tab[1].THAT returns 123 -- How can I use SQF to do this??

another thing I'm confused about. When I try to use _Array select are the first indexed values 0 or is it 1?

Edited by liebstpanzer

Share this post


Link to post
Share on other sites

Array index starts at 0.

http://forums.bistudio.com/showthread.php?100559-Beginners-guide-Arrays

.rpt which is error log is located at

"C:\Users\UserName\AppData\Local\ArmA 2 OA"

to print to .rpt

To print to .rpt example:
diag_log text format ["Items: %1", _items];
Items could be any thing. _items is a real variable.

print in chat:
if (side player == west) then {
player sideChat "You have 20 minutes to Deffensive Objective";
player globalChat "You have 20 minutes to Complete your Objective";
};

hint command can print on screen upper right.
if (local player) then
{
hint "Custom message";
};

Some useful links:

http://forums.bistudio.com/showthread.php?74092-Mr-Murray-Editor-Guide/page2

http://forums.bistudio.com/showthread.php?78089-Mission-Editing-and-Scripting-Information-Links-only-NO-Discussion

forEach looks good.

The mission file.pbo must be depboed and will make a folder. That folder has all the scripts in text files.sqf

It goes here in order to make accessible by game editor.

"C:\Users\UserName\Documents\ArmA 2 Other Profiles\Jigsor=BMR=\MPMissions"

You'll need a tool to unpack the pbo such as:

http://www.armaholic.com/page.php?id...=PBO%2BMANAGER

You C++ interpretations are at least interesting if not functional.

Edited by Jigsor

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  

×