Type Trouble
BlitzPlus Forums/BlitzPlus Beginners Area/Type Trouble
| ||
I've been using the Blitz Plus User guide to assist me with my programming develope me. I'm making a bunch of stupid little tests and I see that a type section has been neglected in the manual. My question is how do you define a type, by what you called it or _type etc.? |
| ||
if you wanted to make a type called "baddie":type baddie ; this declares the type field xpos# field ypos# field speed% ; these are the attributes that each instance of the type will have end type and then to make a few new instances of the type you can say: for i = 1 to 10 anythingyoulike.baddie = new baddie anythingyoulike\xpos = rnd(1,200) anythingyoulike\ypos = rnd(0.1,10.333) anythingyoulike\speed = rnd(1,55) next this makes a list of 10 instances of the type baddie, with random values for each attribute. so now youve made a list of types. to cycle through each of them: for john.baddie = each baddie john\ypos = john\ypos+10 ; moves each instance down 10 pixels next to access the first one of the list: fred.baddie = first baddie to access the last one in the list: beatrice.baddie = last baddie to access the third one in the list jemima.baddie = first baddie jemima.baddie = next baddie jemima.baddie = next baddie neil |
| ||
Thanks alot, this will help me out with a A.I Test I'm making. |
| ||
If you don't want or can't always fetch the value from the type by searching it from beginning to the end, you can do this:; Create the type Const Entries% = 1000 Type array Field name$, value#, age% End Type ; Create type content Dim this.array(Entries%) For i% = 1 To Entries% this(i) = New array this(i)\name$ = "Andres #" + i% this(i)\value# = Rnd(0, 1) this(i)\age% = Rand(10, 20) Next ; Access the type For i% = 1 To Entries% Print this(i)\name$ + " is " + this(i)\age% + " years young and hi's value is: " + this(i)\value# Next WaitKey I've used it for servers so i don't need to SEARCH for a connection's entry, i just ise it's id. |
| ||
cool, i didnt know you were allowed to do that. i guess we both learned something here! neil |
| ||
Interesting concept, thanks for the help guys- but when you define a type lets say you just wanted to change x and y values... but theirs another Field value in the type. How would you do that? |
| ||
sorry, i dont understand what youre getting at... neil |
| ||
For example: Type EnemyShip Field x,y Field health,bullets End Type If I wanted to move the enemy to a different area without changing the health and bullet values what would I do? Would I just say.EnemyShipx etc.? |
| ||
For this.EnemyShip = each EnemyShip If this\id% = IDToMove% Then ; For example if you want to move a specific EnemyShip this\x% = rand(0, 100) this\y% = rand(0, 100) EndIf Next |
| ||
Yes you can change the x and y values without changing the health,shield,etc.. |
| ||
Would what I did in my last post work to change just those values? |
| ||
Yes, you can choose what ever field you change in a type. Though you can use them if you need: The more health you got, the faster you'll move: this\x% = this\x% + this\health% |
| ||
After declaring your type you have to initialize it to use it. Have a look at this.type ship field x,y field health,armor,speed end type That will declare your type. Now you must initialize it like this: enemy.ship = new ship enemy\x = 400 enemy\y = 300 enemy\health = 100 enemy\armor = 10 enemy\speed = 5 Your ship type is now set with starting values. Now if you wanted to move it up the screen, you would do that like this: enemy\y = enemy\y - enemy\speed That would move the enemy ship up the screen 5 pixels per frame. If you wanted to move it to the left, you could do that like this: enemy\x = enemy\x - enemy\speed I hope this helps. Happy coding! |
| ||
Thanks, for the assistance I think I'll be fine now. |
| ||
Sorry, but does anyone know how you assign an image to a type? |
| ||
Add another field to store the image's handle, then (after using New) use that field with LoadImage or CopyImage. |
| ||
this.array = new array this\image1% = loadimage("") this\image2% = createimage() this\sound% = loadsound("") |
| ||
Thank you, this will help me with my A.I engine I'm developing-PurpleGeist(); yes I know peculiar name but its coming soon... when I'm done with it I'll be posting it on the Blitz Showcase. |