Types
Blitz3D Forums/Blitz3D Beginners Area/Types
| ||
I have a question about types:Type bob Field hi End Type count=0 Repeat a=Input("Number") a.bob = New bob a\hi = Rnd(8,79) count=count+1 Until count=3 While Not KeyHit(1) access=Input("What would you like to access?") Print access\hi Wend Would this be possible - say they entered 1, 3, 4. Then they called up 3 would it give them the random number? I tried it out and it came up with errors so would there be any other way of doing this? |
| ||
Your code indicates a lack of understanding of types. That's okay, cause they're weird. Try this: Type bob Field hi End Type count=0 Dim BobArr.bob(20) ; makes an array of 20 "bob" things For i = 1 To 20 BobArr(i) = New bob ; initalizes all the "bob" things Next Repeat a=Input("Number from 1 to 20: ") BobArr(a)\hi = Rnd(8,79) ; puts random number in "bob" number a count=count+1 Until count=3 While 1 access=Input("What would you like to access? Enter 0 to exit. ") If access = 0 Then Exit Print BobArr(Access)\hi Wend End This code will crash if you enter a number below 0 or above 20. If you have further questions about the example above, lemme know. |
| ||
Thanks alot! :) I haven't been doing blitz for very long and i can understand most of it...apart from types! I am trying to make a very basic multiplayer game and i wanted to store the co-ordinates of the player in a type. But i also wanted to be able to add players as they came on. I thought about creating one array and then creating an identical, back-up array so that when a new player joins it would redim the first array to the new number of players, copy the back-up information over to the re-dimmed array then add the new players information to the new array (and then creating the new back up) I know that the explanation was very long but would that be possible? Thanks for any help that can be given, Matt. |
| ||
You could do it that way. But I think you're better off making the array as big as the maximum number of players you will allow, and then fill it up as you go. Redimming and copying will be a relatively slow operation. |
| ||
Ok, thanks for the advice! |
| ||
Glad to help. Good luck! |