FAQFAQ    Board RulesBoard Rules    SearchSearch    LotteryLottery    RouletteRoulette    UsergroupsUsergroups
     RegisterRegister  ProfileProfile    Log in to check your private messagesLog in to check your private messages    Shop    Log inLog in 
View posts since last visit View your posts View unanswered posts

A beginner's guide to variables by AsaSK

 
Post new topic   Reply to topic    Mafiascene.com Forum Index -> Modding Tutorials
View previous topic :: View next topic  
Author Message
AsaSK

Mafiascene Veteran Modder
Mafiascene Veteran Modder


Joined: 24 Feb 2013
Posts: 556
Location: London, England
7696 Bank Notes
Items

PostPosted: Wed Aug 21, 2013 11:24 pm    Post subject: A beginner's guide to variables by AsaSK Reply with quote

Variables, 'flt's or "if" statements can be very confusing if you don't have much experience with them, and little was known about them when I first started modding so it took me years to pick up.

However, now more is known and more modders are starting to use them I thought it would be helpful to introduce them to those who aren't quite sure about their use Smile

However complicated they may seem, variables are incredibly simple.

If YES (1), what happens?
If NO (0), what happens?


In a Mafiascript context, variable scripts are made up of two parts:

1. The 'assignment' command (defining what will be measured)
2. The 'result and consequence' command (defining what happens if the condition we're measuring turns out to be true or false)

For example:

We could pick a command like "human_isweapon XX, YY, ZZ", which measures whether actor XX has weapon ZZ (ZZ being the weapon ID) and stores the resulting 'yes' or 'no' in YY (the name (has to be a number) of a variable that you can choose*).

So, the first half of our script would look like this:

dim_flt 2
dim_act 1

findactor 0, "Tommy"

label CHECKFORCOLT
human_isweapon 0, 1, 9


The script above is asking if actor 0 (defined as Tommy in this script) has weapon with the ID 9 (which is the Colt 1911). It will store the result (yes or no, 1 or 0) in a flt that I have named 1 (the YY number in the middle).

So, now comes the second part of the script: What to do with the resulting 'yes' or 'no' from the previous half of the script that is stored in flt 1.

This is where "if" statements come into play. If statements look like the following: if flt[WW] = XX, YY, ZZ, where WW is the name (number) of the flt (variable), XX is the value that it has to be (1 (yes) or 0 (no)) for the script to jump to label YY. If flt[WW] is not the value of XX (1 or 0) then the script will go to ZZ. Normally ZZ is set to the label at the start of the script, so that it keeps checking and re-checking (in this case) whether the player has a Colt 1911 in their possession or not.

So, the second half of our script would read:

if flt[1] = 1, GAMEOVER, CHECKFORCOLT

label GAMEOVER
endofmission 0


The script above is now telling the game that if the flt named 1 returns a value of 1 (yes) for the player having a Colt 1911, it should jump to the label 'GAMEOVER', which can be seen below as ending the game via the "endofmission" command. If the value is returned as 0 (no), then the script will jump to the label of the script shown before this one, labelled 'CHECKFORCOLT'. This will run the script again an infinite number of times in a loop until the player picks up a Colt 1911.

*You can name the flt whatever number you like, as long as you have allowed for that many 'flt's at the start of the script (if you name the flt '9', you would have to write "dim_flt 10" at the beginning in order for the game to recognise up to 10 'flt's (0 counts as one).

Hopefully this hasn't fried the brains of those reading it too much, just go over it slowly and replicate each stage with your own script step-by-step. Once you've mastered "if" scripts you can do all sorts of things so give it a try and, as always, ask here if you need any help

Good luck!
_________________

The official Mafioso Mod thread
Back to top
View user's profile Send private message
AsaSK

Mafiascene Veteran Modder
Mafiascene Veteran Modder


Joined: 24 Feb 2013
Posts: 556
Location: London, England
7696 Bank Notes
Items

PostPosted: Wed Aug 28, 2013 8:04 pm    Post subject: A beginner's guide to variables by AsaSK Reply with quote

Also, soon I will be putting up a visual guide to compliment this Smile
_________________

The official Mafioso Mod thread
Back to top
View user's profile Send private message
MatteoCapoletti

Mafiascene Veteran Modder
Mafiascene Veteran Modder


Joined: 05 Mar 2013
Posts: 503

964 Bank Notes
Items

PostPosted: Thu Aug 29, 2013 1:55 am    Post subject: A beginner's guide to variables by AsaSK Reply with quote

very nice stuff!
Applause Applause Applause Applause
Back to top
View user's profile Send private message
AsaSK

Mafiascene Veteran Modder
Mafiascene Veteran Modder


Joined: 24 Feb 2013
Posts: 556
Location: London, England
7696 Bank Notes
Items

PostPosted: Sat Aug 31, 2013 6:40 pm    Post subject: A beginner's guide to variables by AsaSK Reply with quote

Thanks Matteo, old news for you of course Wink
_________________

The official Mafioso Mod thread
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Mafiascene.com Forum Index -> Modding Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

Generation Time: 0.015 | Queries: 19