Little help with types
Blitz3D Forums/Blitz3D Beginners Area/Little help with types
| ||
I have 4 collections of playerdata player1.playerdata player2.playerdata player3.playerdata player4.playerdata So far I've been using FOR EACH NEXT to loop through each collection. I'm a little puzzled as to how to implement what I need to do next... For collision detection I need to compare: player1\x with player2\x then player1\x with player3\x then player1\x with player4\x Can someone advise the best way to do this as I'm new to types and lacking any good documentation. |
| ||
Since you have distinct handles to the four type instances, you can use those names directly in your code. Exactly as you've written it in fact, just make sure to declare the type instances as global so that the handles can be used inside of any function. A For/Each/Next loop is unnecessary. The code would be: (at the top of your code declare global handles for the type instances) Global player1.playerdata Global player2.playerdata etc (also at the top of your code, declare the playerdata type) Type playerdata Field x End Type (somewhere else in your code, possibly inside a function, create the type instances) player1.playerdata = New playerdata player2.playerdata = New playerdata etc (now access the fields of those instances anywhere you want) If player1\x > player2\x etc |
| ||
I'd like to add that I need to do the above as part of a FOR EACH NEXT LOOP My main program loop involves For loop.playerdata = Each playerdata ; compare loop\x with player2\x ; compare loop\x with player3\x ; compare loop\x with player4\x Nexy |
| ||
Thanks Joe - I've managed to do all you've mentioned already. My problem comes when trying to do the comparison as part of my main game loop as mentioned above |
| ||
Way to add that little wrinkle AFTER I spent a couple minutes responding. |
| ||
One way of doing this would be as follows: In your type have a field PlayerID, example Type PlayerData Field x field y field z field PlayerID end type then do the following: For player.Playerdata=each playerdata if player\playerid=1 then for otherplayer.playerdata=each playerdata if player\playerid<>otherplayer\playerid then "Compare the two players x .." next endif next There are better ways of doing this though, for example you could make an array of types (see the custom types documentation in blitz) and do the check as follows: type playerdata field y field z field x end type dim player.playerdata(4) for i=0 to 4 player(i)=new playerdata next for i=2 to 4 "compare" player(1)\x with player(i)\x next |
| ||
I'm sorry about that! |
| ||
thats great guys - thank you |
| ||
just implemented it in my game and my car to car collision is working perfectly! thanks Matty for the code and JHocking for your patience |