types

BlitzPlus Forums/BlitzPlus Beginners Area/types

Kyler(Posted 2007) [#1]
When i uses types i always do something like this...

enemy.enemy = new enemy

but i see people do this...

enemy.ship = New ship

what does it do? could somebody give an example?


Yo! Wazzup?(Posted 2007) [#2]
I have the same question... I always got frustrated in types because I didn't get this:
a.b = ab
What does ab stand for?
or
r.t = qwerty
What does qwerty stand for?


Réno(Posted 2007) [#3]
"enemy.ship" is a "variable" who can be local or global from your Type "ship".

So, you can make different "variables" as "car.ship" or "jumper.ship", etc.

"enemy.ship"
>"ship" is the parent variable of Type "ship".
>"enemy" is the child variable of Type "ship".

I hope I didn't say bad things...

-_'


Alaric(Posted 2007) [#4]
Yeah... types can be pretty confusing if you are new to programming. Think of it like this. If you write "a.b = new b" then a is a variable just like any other. But, variables also come in different formats. For example, string variables hold letters and numbers while "normal" variables only hold numbers. Each "type" that you define basically creates a whole different format of variable, and just like you would add a $ to make a variable hold a string, you have to add the ".b" to make the variable "a" hold data of that format. But now comes the interesting part. As you probably noticed, the whole point of types is to allow you to store more than one variable into a single container variable, and the each type holds different variables than every other type. This is why you have to add the .typename or ".b" in my example to the end of each variable when you first declare it.

Now for the (even more) confusing part. The variables that you declare as .typename aren't really holding the data that you access when you use the \ to access the subvariables. The subvariables are actually being held somewhere in blitz's memory. That variable "a" only tells you where you can find those subvariables in memmory. This means that you can change the contents of the variable "a" without destroying the data which it points to. However, unless you store the place it points to into another variable declared with the same ".typename" suffix (like "a.b =c.b"), you can't get back to it (for the most part). Blitz does keep track of the times that you use the "new" statement to actually create a set of subvariables for "a" to point to. You can access this list the the "for a.b = each b" line of code that you might have seen elsewhere.

I hope that this clears a few things up for you... sorry if it just makes things worse.


Kyler(Posted 2007) [#5]
i think i understand. sorta. Im making an RTS. If i want to create diffrent types of buildings do i do this?

castle.building = new building
farm.building = new building
barracks.building = new building
tower.building = new building
etc.


Alaric(Posted 2007) [#6]
That depends. What do you mean by "types of buildings"? Do you want each different building to hold different data than the other ones, or do you want the different buildings to hold different data formats? Put a little bit simpler, do you want your subvariables to be all the same (so each subvariable might still hold different numbers). For example, do you want all of the buildings to have a "peasantnumber" variable, or do you just want to have castle.building variable named "peasantnumber". Also, you need to declare the type before you can use it. So, if you are just using a single type, you would need something like this in your code.



Here's an example of what you can do with this type declaration. Hopefully it will clear a few things up, as well as give you some useful tricks.




Siopses(Posted 2007) [#7]
Also, you could look at my Type Trouble query to help
you even more with types.


H&K(Posted 2007) [#8]
Just to add my two pee.

If you make for yourself a strong nameing ethic that you stick to then things like this become less of a hasstle.

For example All my "Types" are preceded with T, so
enemy.enemy = new enemy
would be
enemy.TEnemy = new TEnemy
If its going to be one of many (In a list for example)
AnEnemy.TEnemy = new TEnemy
etc
I could give more examples on how I name fields and the such, but the point is, pick a nameing the things policy that makes sence to you. And then stick with it.