Beginning types
Blitz3D Forums/Blitz3D Beginners Area/Beginning types
| ||
Hello everyone, I am trying to learn to use types to make my game design more structured. However, I don't understand how they work. Can someone tell me why this code doesn't work? All I want is to be able to access the data within a type variable. The tutorial included in the IDE says this is how it's done, unless I am misunderstanding it. AppTitle "Types Test" Type player Field name Field x Field y Field lives Field bullets_left End Type p.player = New player p.player\name="John" p.player\x=10 p.player\y=20 p.player\lives=5 Print p.player\name WaitKey End |
| ||
You have done everything correctly except declare the type of variable. For string variables you need to add '$' to the variable name should be name$ Also you don't need to put print p.player\name just put p\name as you have told blitz p is of type player. |
| ||
Although you only need to add the $ after the "String" variable, you should get into the hang of always putting the type of variable at the end of its name in the declare (ie #) Also, while the advice that you dont need p.player is correct, as a nameing convention it "could" be a good idea ie. First\x =20; Second\x = 20 or First.Player\x =20 ; Second.Player\x = 20 |
| ||
Right! It works just like you said. I don't understand how I could've been so dense as to forget the $ :). About the p.player thing, it works both ways it seems, but I prefer the shorter version (I understand it better). Thanx for your replies!! |