Games   Calendar
Using variables and arrays

 
Post new topic   Reply to topic    Life's a Game, Play Forum Index -> Map making
View previous topic :: View next topic  

Was this tutorial helpful to you?
Yes, I learned alot!
75%
 75%  [ 3 ]
Yes, I learned some
0%
 0%  [ 0 ]
I learned alittle, but not much
0%
 0%  [ 0 ]
Nah, I knew it all already
25%
 25%  [ 1 ]
No, it's too advanced for me
0%
 0%  [ 0 ]
Total Votes : 4

Author Message
Athene
Site Admin
Site Admin


Joined: 26 Jan 2005
Posts: 151
:
Location: Oslo, Norway

Items

PostPosted: Sun May 15, 2005 12:47 pm    Post subject: Using variables and arrays Reply with quote

Variables can be confusing the first times you try them out. Like when to use integer and real, what is an array, how to be effective with large numbers of players and variables etc.
I'll give you a short introduction to the most important things.

Integer is the most common variable. It's used for counting levels in TDs, counting number of players, counting units, counting of everything that is always in whole numbers.
Real is used for all numbers with decimals, like income in tw's. It is also used for Timers, if you want to use variables to define how long the timer should run.

Integer variables can easily be converted into real variables with no complications. Converting a real variable into an integer would cause you to lose the decimals in the real variable.

Boolean is used for conditions that are true or false. You can use it to check if a player is an ally of another player, check if a unit is air\ground\hero etc, check if a hero has a certain item, check if a unit is still alive, etc. When both integers and booleans are suitable for a purpose, booleans are often easier to use.
Ability includes skills, and is a good thing to have in some maps where heroes are important. Like in Build or Fight you will choose an ability you want, and that ability will stick with you for the rest of the game. To do this, you will have to set the chosen ability to an ability variable, and when a hero levels up, you will use that variable to specify what ability should level up. ATM I can't find the trigger doing this, but I think it's the "hero - learn" action(and not the "unit - add ability").
Destructible is used for doodads, and are needed for instance if you want something to happen when a doodad is destroyed.
Dialog is needed to make dialogs. Make a dialog variable with the name of the dialog you will make, and then use "show Dialogname for Picked Player" or whatever you want.
Dialog Button is also needed to make dialogs. You will need one Dialog Button for each button in the dialog, and you should name them after what you will write at the buttons in the dialog.
Then use "Dialog - create dialog button" to add each button to the dialog, and "set DialogButton1=last created dialog button".
Item is used if you want to trace a specific item (item, not item type). With this you can make conditions like "Hero has Item equal to true".
Item type is amost the same as Item, but this is for all items of the chosen item-type. The corresponding conditions would be "Hero has item of Item Type equal to true". This is how I made items merge in Build or Fight.
Leaderboard is not very important. You dont need a variable of this type to make a leaderboard, it's probably for making several leaderboards at a time. When you have 1 leaderboard, it's better to use "last created leaderboard". I've never used more than one myself, and I've never seen anyone else use more than one, so you dont have to care about this.
Multiboard is the same as Leaderboard, but with multiboards. Noting to care about.
Player is used to trace a certain player. If a player starts a chain of triggers, and you need to refer to the player that started it, use this variable. Unless you need to refer to the player in several triggers, "triggering player", "owner of killing unit" etc is usually better to use.
Region has not been very important to me so far. it can be used with an array in survivor TDs to refer to regions for each player, but other than that I never use it.
String is used for text (no shit:p). It can for instance be used for showing game tips to the players. It could also potentionally be used for making the game chat with a user. Not that I see any point in that right now, but there's an event with "player typing a message containg String", a condition with "entered chat string equal String" and actions for giving messages back. use your imagination:)
Tech-Type is used for upgrades and researches. Let's say you make an aos like game with factions fighting eachother, and you want the players to research increased unit productions for the team. Then use "unit finishes research" and "researched tech-type equal to TechType" to start corresponding actions.
Timer is just like the leaderboard variable and the multiboard variable. Having more than 1 timer is more common though, so use this to refer to the right timer when you have more than one running.
Timer Window is for refering to the window showing a certain timer. I dont think I ever used this.
Trigger is a funny one. I still cant think of any good use for it...
Unit is like Item, but with units. Use it to trace a certain unit, like checking if the unit is in a specific region, if the unit has a specific item, if it has a specific ability, if it's alive, etc.
Unit Group is not much used I think. You can for instance use it in TDs, as a way of checking when all creeps are dead, and when to launch next level. You can also use it as another way of counting units in an area or unit matching conditions, but it would only save you tiny amounts of time and work in most cases.
Unit-Type is like Unit but includes all units of the same type. Variables with Unit-Type are not much used, but can be important. If you make a map where the players can choose their own unit-type, and the players will recieve new units of this type through the game, then use this variable.

And that's all the variables you should know. The rest is rarely used, and only in special cases.
Now over to arrays.
Arrays are never completely crucial, but alway useful almost nomatter what kind of map you are making.
Take a Unit variable as an example. 1 regular Unit variable can have 1 unit in it. To refer to that one unit, you only need to refer to the variable. You may think of the variable as a drawer, with space enough only to 1 unit.
Code:
Set tutorialUnit = Footman 0108

Then make that variable an array. It will now have infinite(in theory) space for more units! That's one of the reasons why arrays are so useful. Then you might think "but how do you refer to each one of those units?" That's the other good thing, because using a variable with array is actually just like using 1 variable for each unit.
Let's say all players have 1 unit each that you want to put into this variable, while you want to be able to refer to these units later too.
Then do "set UnitVariable[1]=player 1 unit", "set UnitVariable[2]=player 2 unit" and so on. See, now you can refer to each one of them, because you have one drawer for each player
Code:
Set tutorialUnit[1] = Footman 0108 <gen>
Set tutorialUnit[2] = Archer 0110 <gen>
Set tutorialUnit[3] = Ghoul 0043 <gen>

So how do you put 2 units for each player into this variable, while still being able to refer to all of them?
Now it start's getting complicated. Imagine the drawers turning into a shelf. Each player has one row in the shelf, and there are infinite collumns. How would you tell a person to pick out the right book from a shelf like that? You would need to know the collumn number, and ask the person to get the book from that collumn.
Same with these units, you need to identify each collumn and row with a number. So make an integer variable with array, and use that to identify each collumn.
Code:
Set TutorialInteger[1] = 1
Set tutorialUnit[TutorialInteger[1]] = Footman 0108 <gen>
Set TutorialInteger[1] = 2
Set tutorialUnit[TutorialInteger[1]] = Footman 0109 <gen>
Set TutorialInteger[2] = 1
Set tutorialUnit[TutorialInteger[2] = Archer 0110 <gen>
Set TutorialInteger[2] = 2
Set tutorialUnit[TutorialInteger[2] = Archer 0111 <gen>

At this point, you'll easily get confused. But although this is the way that saves you the most time and space, there is another way which is not that confusing. Make an integer variable without any array, one for each player.
Code:
Set TutorialIntegerPlayer1 = 1
Set tutorialUnit[TutorialIntegerPlayer1] = Footman 0108 <gen>
Set TutorialIntegerPlayer1 = 2
Set tutorialUnit[TutorialIntegerPlayer1] = Footman 0109 <gen>
Set TutorialIntegerPlayer2 = 1
Set tutorialUnit[TutorialIntegerPlayer2] = Archer 0110 <gen>
Set TutorialIntegerPlayer2 = 2
Set tutorialUnit[TutorialIntegerPlayer2] = Archer 0111 <gen>

That's better, isn't it?Smile

So what do we use arrays for? This should give you some ideas:
Code:
Unit Inits
    Events
    Conditions
    Actions
        -------- Level 1 --------
        Set Monstertype[i] = Level 1
        Set MonsterCount[i] = 20
        Set AmountGold[i] = 50
        Set i = (i + 1)
        -------- Level 2 --------
        Set Monstertype[i] = Level 2
        Set MonsterCount[i] = 20
        Set AmountGold[i] = 55
        Set i = (i + 1)

In Massacre TD, I've used arrays for choosing what unit types will spawn each level, how many units will spawn each level, how much gold you will get between each level, and you can also use it to show tips at the end of each level. This is is a much easier way to launch the levels than using something like "if level=1 then create level 1 units, if level=2 then create level 2 units" etc.
Code:
kills
    Events
        Unit - A unit Dies
    Conditions
    Actions
        Set Kills[(Player number of (Owner of (Killing unit)))] = (Kills[(Player number of (Owner of (Killing unit)))] + 1 )
        Set Deaths[(Player number of (Owner of (Dying unit)))] = (Deaths[(Player number of (Owner of (Dying unit)))] + 1 )
Set Units[(Player number of (Owner of (Dying unit)))] = (Units[(Player number of (Owner of (Dying unit)))] - 1)

In Advanced Battle Arena I've used arrays to note how many kills, deaths and units each player has.

Other things you can use arays for: Creating different kinds of player units for each player with each interval, giving a playerchosen skill to all units owned by that player, giving different amount of gold to all players, identifying each player's hero in hero games, +++ use your imagination

Good luck making use of your new knowledge:)


Last edited by Athene on Fri May 18, 2007 6:50 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
XsiX
Familiar
Familiar


Joined: 22 Apr 2005
Posts: 52
:
Location: Denmark

Items

PostPosted: Sun May 15, 2005 11:40 pm    Post subject: Reply with quote

once again i must say, i am impressed of your way to cut things out to pieces so even noobs like me can almost understands it Razz
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Life's a Game, Play Forum Index -> Map making All times are GMT + 1 Hour
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

Life's a Game, Play topic RSS feed 


Digital Dementia © 2002 Christina Richards, phpBB 2.0.6 Version by phpBB-fr-themes
Powered by phpBB © 2001, 2005 phpBB Group

 

FREE FORUM HOSTING by AtFreeForum. Terms of Service - Privacy Policy
FASHION ACCESSORIES - BLING BLING - LADIES WATCHES - KOREAN CHILDREN CLOTHING - ONLINE BARGAIN STORE - FASHION JEWELLERIES