Firstly, I have discovered how variables can be assigned a different way, giving more type options. And those options are:
- BYTE, which can hold a number up to 255 from 0
- WORD, which can hold a number from 0 to 65536
- DWORD, which can hold a number from 0 to 2147483647
- INTEGER, which can hold a number from -2147483647 to 2147483647#
- DOUBLE INTEGER, which can hold a number from -9223372036854775807 to 9223372036854775807
- FLOAT, which I dont quite understand how much it can hold
- DOUBLE FLOAT ^^
- BOOLEAN, which despite being a true/false variable can hold a number from 0-255, 0 being false and any above being true.
- STRING, which does not say how much it can hold.
They all have different byte sizes, so I am depicting that using the correct on at the right time can save a little space, not including BOOLEAN which has a more useful function.
All these types can be given to a variable by simply writing: Variablename AS Variabletype. For example
- age AS BYTE
Though this way is just a way of defining a variable before its use, as it needs to be given a value first. I actually prefer this way because its easier to type. I have to stop and look at the symbols, but instead I can rather write them fluently. Futhermore, you do not have to put any symbol when you use it, as the variable becomes the type given for the rest of the program. The only downside to this, is that you cannot see what the variable is by looking at it, you would have to go to the place where you defined it.
As well as learning this so far, I have also came across the usage of TYPES. They are simply given variables a structure, and several sub-variables. For instance, if you had a player in a fantasy game, then you could simply define a type like so, giving it all the variables for the players stats:
- TYPE PlayerType
- strength AS INTEGER
- defense AS INTEGER
- intellect AS INTEGER
- dexterity AS INTEGER
- willpower AS INTEGER
- ENDTYPE
That way, you have grouped the variables. You would then need to define a variable a type so:
- player AS PlayerType
Now when ever you want to access the variables (Called records), you just type "Player.record", lets say I wanted to increase the players strength by 10, I would write:
- player.strength = player.strength + 10
Now you can see how useful this could be, as you can see what variables belong to which, but more over, something even more useful would be to use a type for an enemy in a fantasy game, so considering they have all the stats as given above, you do not have to define a variable for every enemy, instead you can define it as a "PlayerType" and access the records.
Array cells can be come types also, but you cannot have an array as a record.
This is all that has been taught so far in this chapter, and you can see that it is a lot! The next part deals with more array functions, such as inserting extra cells and deleting excess ones. Every chapter I read I feel brings me closer to independent creation of games, and I am starting to think how certain genres and situations can be created using what I have learnt.
No comments:
Post a Comment