Home   Help Search Login Register  

Author Topic: GEN. Scripting Help??  (Read 2216 times)

0 Members and 1 Guest are viewing this topic.

Offline NightJay0044

  • Former Staff
  • ****
  • Let's make OFPEC great again
    • My Steam Workshop
GEN. Scripting Help??
« on: 19 Aug 2005, 06:55:18 »
All right I'm starting to understand scripting from start to finish and I need help. Right now I'm trying to learn from "Johan Gustafsson" scripting tutorial. I'm on a script where you are "Passing string to a script"

Ok first of all, "What is a Sring?"

Second, what exactly does this line mean below in step-by-step detail?

_msg = _this select 0

I've tried scripting before, never got anywhere with it, it's confusing for me but I know with my own effort know and wisdom from you guys I can accomplish it. Ok Got to modify this

Before I even go onto scripting, what do I need to have a complete understanding of first before I even think about enhancing my missions?
« Last Edit: 19 Aug 2005, 07:04:00 by NightJay0044 »
Who's hyped for Arma4, long live Arma!

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:GEN. Scripting Help??
« Reply #1 on: 19 Aug 2005, 08:15:38 »
m'kay - short scripting lesson 101 :)

variables - they are very handy, they are basically words which you introduce to flashpoint saying "hi flashpoint, i'd like you to meet my good friend variable_name; variable_name is a plumber, enjoys skiing and plays the flute."

and flashpoint says "hey variable_name, pleased to meet you."

so variables are quite powerful things. they can be numbers, or they can be words. when a variable is a word, it's called a 'string'.

so if i was to say

Code: [Select]
my_number = 10
that would store the value 10 in the variable my_number. i could then use it like any other number, for multiplying, division, addition or subtraction. however, if i say

Code: [Select]
my_number = "ten"
that stores the string 'ten' in the variable my_number. since it's a word, you can't do anything mathematical with it. what you can do is add it to other strings to make a sentence, thus:

Code: [Select]
my_street = "springfield terrace"
my_town = "loonsville"

my_address = my_number + my_street + my_town

so the variable my_address would hold the value "10springfield terraceloonsville". note the lack of spaces. you need to put those in ;)

on to your second question.

Code: [Select]
_msg = _this select 0
this is a wee bit more complex, but stay with me, as this is a fundamental that you should learn.

first of all, variables can be global (which means they can be seen from all points in flashpoint, all the time) or local (which means they are used only in the script where they appear, and then disappear). whenever you see an underscore ( _ ) before a variable name, that means it's a local variable.

in other words, _msg is a local variable, and will only be recognised within its own script. you could call a variable _msg in another script, but the second _msg will hold different values for the second script. the two are separate, even if they have the same name.

next comes _this. there's a whole tutorial on _this in which general barron explains it better than i could. find it here.

next comes the select 0 part, and again, this is a cornerstone of flashpoint scripting.

arrays. let's go back to the address example. my_address holds one long string, a single address. what if you wanted a phonebook? well, you could create all those variables and do it all by hand, which is tedious.

address1 = blah blah blah
address2 = blah blah blah
address3 = boring boring boring....

you get the idea. alternatively you could create an array. this is a special kind of variable which can hold multiple variables, and indexes them numerically. arrays are defined by square brackets []. again, there's an exellent tutorial by dinger here which will show you what's what, but in a nutshell arrays store values against an index, starting at 0. so if you say

Code: [Select]
my_array = []
my_array = my_array + [my_address]
my_array = my_array + [my_address]

then there will be two copies of the address stored in my_array. to get at these values you use

Code: [Select]
a_value = my_array select 0
b_value = my_array select 1

now a_value holds the first address, b_value the second.

so to summarise:

Code: [Select]
_msg = _this select 0
creates a local variable called _msg, and makes it hold the value found at the first position in the array _this.

as an aside, stick with scripting. it's easier than you might think at first. it's like any other language - once you have the basic vocabulary down, you can start forming some complex sentences. and once you get more experience, you can begin to make your scripts sing  8)
« Last Edit: 19 Aug 2005, 08:19:22 by bedges »

Offline Speeder

  • Members
  • *
    • OFP.nu
Re:GEN. Scripting Help??
« Reply #2 on: 19 Aug 2005, 14:42:35 »
that was one of the very best explanations I've seen in a long time. thanks, now I understand this stuff to.

But basicly you can only use arays for one thing. hold a number of informations, count the totalt number of entries, and use the first intry, as you can never know what place the other entries has.

But, if I substract one entry from the array, will the array then collaps, or will it hold the struckture, and then fill out the blank spot when next entry is added? How will my array look ?



There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline NightJay0044

  • Former Staff
  • ****
  • Let's make OFPEC great again
    • My Steam Workshop
Re:GEN. Scripting Help??
« Reply #3 on: 19 Aug 2005, 16:06:46 »
Ok. I'm still confused on scripting,  I think I'm just Scripting illiterate. I under stand the local and global varialbe a little bit. I understand how to run a script in the game. I understand basic things.  Barely even that.

When it gets into actually using scripts for what I want, I sit there and say "What, blah blah blah". Scripting is cool but I wish I Understood it more. But Maybe I can try and sit there and slowly read the Scripting tuts and understand and ask questions about certain things, unless somebody else has any other advice?  Right now I'm learning about the commands you put in the INITIALIZATION FIELD: of a trigger/waypoint and unit.

So that's a start.  Anybody have advice on my next step I can do, should I start making example missions for myself that use the codes I just learned before I move on??

Thanks all.

Who's hyped for Arma4, long live Arma!

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:GEN. Scripting Help??
« Reply #4 on: 19 Aug 2005, 16:28:09 »
m'kay. say we have an array -

Code: [Select]
my_array = ["one","two","three","four","five"]
as you mentioned, we can find out how many elements an array holds using the count command. in this case it will return 5.

say we wanted to know at what position "three" was within the array. first we need to know if "three" even exists in the array, like this:

Code: [Select]
is_there_three = {_x == "three"} count my_array
is_there_three now holds the number of "three"s in the array, namely 1. so if is_there_three was 0, we'd know "three" wasn't part of that array.

now we know there's a "three" in there, we want to know where in the array it is. so we set up a counter in a loop, like so:

Code: [Select]
_i = 0
#loop

is_this_three = my_array select _i

?is_this_three == "three" : hint format ["Three is at number %1 in the array"], _i]; exit

_i = _i + 1
?_i >= (count my_array) : hint "There is no three."; exit

goto "loop"

let's go through that line by line.

  • first a variable (_i) is created to use as a counter and set to 0, the first index of the array.
  • then comes the loop marker (#loop).
  • we put the value of the array index pointed at by _i into a new variable (is_this_three).
  • then we check if that new variable is equal to "three". if it is, a hint is displayed telling us at which counter value "three" was found, and the script exits. if not, it continues to the next line.
  • we move the counter variable _i foward by one.
  • then we check if the counter has reached the total number of entries in the array. if it has, it displays a hint and then exits. if not, it jumps back to the loop marker.

arrays don't collapse, not as far as i know. say i wanted to subtract "three" from my_array.

Code: [Select]
my_array = my_array - ["three"]
my_array would now be ["one","two","four","five"].

subtracting a value from array will remove all instances of that value. the index order of the array would then shuffle downwards, such that my_array select 2 would now be "four", not "three". anything you add into an array goes on the end, so if you wanted to reintroduce "three" in the proper place, you'd have to reconstruct the entire array from scratch, or at least from the index position you want it reintroduced at onwards.

it seems complex stuff, and the learning curve is pretty steep at first. persevere though. it makes missions so much better, as we all know :)

and yes - test, test and test again. experimentation is the best teacher.
« Last Edit: 19 Aug 2005, 16:31:22 by bedges »

Offline NightJay0044

  • Former Staff
  • ****
  • Let's make OFPEC great again
    • My Steam Workshop
Re:GEN. Scripting Help??
« Reply #5 on: 19 Aug 2005, 16:42:08 »
Ummm..sorry man too fast for me..If you willing to teach me, and if you have some sort of instant message service, feel free to either email me or we can chat through there. but it will take some hard effort for me to understand this, thanks...
Who's hyped for Arma4, long live Arma!

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:GEN. Scripting Help??
« Reply #6 on: 19 Aug 2005, 18:05:36 »
NightJay, you have the right tutorial.   The other good one is snYpir's Friendly Intro to Code Snippets.  If you're learning about init lines (which is the best way to start) then Abuu's basic editing tutorial is good.     Devilchaser's Editing/Scripting tutorial is a good alternative view.

Also look at my Tutorial Mission.   It has some very simple scripts which you can see working "in the field".    And read the command reference!
« Last Edit: 19 Aug 2005, 18:06:39 by macguba »
Plenty of reviewed ArmA missions for you to play

Offline Blanco

  • Former Staff
  • ****
Re:GEN. Scripting Help??
« Reply #7 on: 19 Aug 2005, 19:13:55 »
Quote
I think I'm just Scripting illiterate

Nonono, I'm a living example from someone who learned OFP scripting without any programing experience (just a little BASIC from school in the old days)
If I can, everybody can.
 
Search or search or search before you ask.

Offline NightJay0044

  • Former Staff
  • ****
  • Let's make OFPEC great again
    • My Steam Workshop
Re:GEN. Scripting Help??
« Reply #8 on: 19 Aug 2005, 19:53:02 »
 ;D, all beginners have a tough time with scripting, probably. Well I'll give it more of  a shot. Hopefully I'll get somewhere.

Thanks Macguba for the info, yeah i think I pretty much have all those tuts on my pc in my OFP folder. I'll give them a further look.

Okay. Blanco, how did you further advance your knowlege in scripting, what tuts did you learn from that really helped? What I need is something simple and a step-by-step tutorial to get me through it..

????

Any comments, questions etc that could help me feel free to post.
« Last Edit: 19 Aug 2005, 19:55:31 by NightJay0044 »
Who's hyped for Arma4, long live Arma!

Offline Blanco

  • Former Staff
  • ****
Re:GEN. Scripting Help??
« Reply #9 on: 19 Aug 2005, 20:20:42 »
I learned everything by reading the tutorials (no suprises there), trying them out and writing my own personal tutorials with a demomission. (in my own language). Also learn about the format command for debugging, otherwise you never really know what you're doing.

I got one step by step tutorial from daddldiddl named Basic scripting tutorial Operation Flashpoint's Resistance's Scripting language explained.
I don't have the link but wait a min I upload it for ya, it's a pdf document so you need acrobat reader
« Last Edit: 19 Aug 2005, 20:23:15 by Blanco »
Search or search or search before you ask.

Offline NightJay0044

  • Former Staff
  • ****
  • Let's make OFPEC great again
    • My Steam Workshop
Re:GEN. Scripting Help??
« Reply #10 on: 19 Aug 2005, 20:22:08 »
All right, Yeah i have acrobat reader, so go ahead.
Who's hyped for Arma4, long live Arma!

Offline Blanco

  • Former Staff
  • ****
Re:GEN. Scripting Help??
« Reply #11 on: 19 Aug 2005, 20:25:18 »
Here you go

http://users.telenet.be/blanco/Scripts/BasicScriptingTutorial.zip

Ok, I found the link of his site : http://www.gogodot.net/ofp.html
Link : http://daddldiddl.de/downloads/tutorials/BasicScriptingTutorial.pdf

You can also download the tutorial from there.

IMPORTANT *edit*

Download the version from DAddlddil....(what a name  :P) site, I just saw mine is obsolete.


 
« Last Edit: 19 Aug 2005, 20:42:26 by Blanco »
Search or search or search before you ask.

Offline NightJay0044

  • Former Staff
  • ****
  • Let's make OFPEC great again
    • My Steam Workshop
Re:GEN. Scripting Help??
« Reply #12 on: 19 Aug 2005, 20:36:18 »
Thanks blanco!  ;D, never saw this one before, i'll read it and give it a try....
Who's hyped for Arma4, long live Arma!

Offline Speeder

  • Members
  • *
    • OFP.nu
Re:GEN. Scripting Help??
« Reply #13 on: 19 Aug 2005, 20:49:36 »
 
Quote
subtracting a value from array will remove all instances of that value. the index order of the array would then shuffle downwards, such that my_array select 2 would now be "four", not "three".


That's what I ment by Collapsing. But I'm danish - so my vocabulary isn't perfect ;)
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:GEN. Scripting Help??
« Reply #14 on: 19 Aug 2005, 20:57:20 »
Quote
subtracting a value from array will remove all instances of that value
Take care with this.  If the elements of an array are themselves arrays then you cannot remove them in this way.  For example:

_posA = getPos a
_posB = getPos b
_posC = getPos c

_positions = [_posA,_posB,_posC]

Then the line:
_positions = _positions - [_posA]

will do nothing.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re:GEN. Scripting Help??
« Reply #15 on: 19 Aug 2005, 21:18:04 »
Quote
Take care with this.  If the elements of an array are themselves arrays then you cannot remove them in this way.  For example:

_posA = getPos a
_posB = getPos b
_posC = getPos c

_positions = [_posA,_posB,_posC]

Then the line:
_positions = _positions - [_posA]

will do nothing.

So I would have to go about it as so:



_posA = getPos a
_posB = getPos b
_posC = getPos c

_positions = [_posA,_posB,_posC]

_myvar = _positions select 0

_positions = _positions - _myvar   -->>    _positions = [_posB,_posC]   ???
« Last Edit: 19 Aug 2005, 21:27:00 by Speeder »
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:GEN. Scripting Help??
« Reply #16 on: 19 Aug 2005, 23:36:48 »
No.  It still would not work.  You cannot remove an element from an array if that element is an array itself in that way.

Try it and see.
« Last Edit: 19 Aug 2005, 23:37:03 by THobson »