Type Trouble
Blitz3D Forums/Blitz3D Programming/Type Trouble
| ||
I'm no stranger to Blitz3D, but I have a major problem. I'm trying to make a shooting game in which when you touch a weapon to pick it up, the weapon dissappears and returns after 20 seconds. Long ago I bought a book about programming in Blitz3D, which I now use mainly for reference. In this situation it uses the command "Object". Blitz recognizes it by changing the color of the typed word but I can't find it anywhere in the help files. Here's my code (its a bit messed up from the size of this window): If CountCollisions(soldier2)>0 any_weapon.weapon=Object.weapon(EntityName(entity)) HideEntity any_weapon\inactive_model any_weapon\active=True starttimer(any_weapon\inactive_model,any_weapon\timer) conditional(any_weapon\index,2) End If Could someone please tell me what Object is and how to use it here? |
| ||
First this: my_type.foo = New foo type_ID = Handle(my_type) This asigns the my_type instance a unique ID number. Then, you can use this handle to get the type instance it refers to: this_type.foo = Object.foo(type_ID) Since the ID handle is a simple integer number, it can be stored as an entity's name, as in the code you posted. This allows a specific type instance to be linked to an entity. Handle and Object aren't in the docs as they were never made 'official' commands, for some reason. |
| ||
Handle() and Object() are now official. |
| ||
Since when? I don't see how they can be official since Handle() could potentially cause a long-running app to crash. |
| ||
"skid" mentioned it 9 months ago: It mentions some 1.97 specific abilities in the LoadTexture description for instance, and all new commands added uptil now are documented including Object and Handle, finally official! They are both on page 129 of the brand new, PRINTED, Blitz3D Programming Manual ( www.lulu.com/content/388950 ). |
| ||
OK, I'm going to write an app that uses handle that crashes, then report it as a bug. :P |
| ||
Big10p... In what situations is Object/Handle() prone to crash blitz? I use handle in my server code, and it was running for about 3 months straight with no issues. Just kinda curious what to look out for :) |
| ||
The problem as I see it is with Handle. It always returns a unique integer. That number is never re-used for the duration of the program run, even if the type instance it refers to is subsequently deleted. That means that Handle could potentially run out of integers to assign, if it was called enough times on different type instances. The limit must be $7FFFFFFF as blitz uses 32-bit signed integers. TBH, I don't know how Handle copes with this situation if it occurs, but I can't see any other outcome but a crash. Sure, $7FFFFFFF is a very large number and would take a long time to reach, but I guess it's technically possible. |
| ||
I thought it gave out a number that basically amounts to a pointer.. e.g. a memory address, and not a constantly increasing counter. |
| ||
No. The first time you call it, it returns 1, then 2, then 3 etc. It always returns the same number for the same type instance though, obviously. |
| ||
big10p. Thanks for the code, but it doesn't work. The debug reports "Illegal type conversion". Perhaps I should have mentioned this earlier, but I tried numerous other methods of trying to make this work and got this same error almost every time. When I didn't, the whole game changed and after one frame I got the classic "object does not exist" error. puki, I'm afraid I dodn't have the time to read 400 pages to solve problems like this. This seems to be the last big hurdle in my attempt to make this game. This section of a function controls picking up the weapon, activating it and setting all the variables for its operation. Everything else is a piece of cake.:) But , obviously, I don't want my computer to crash |
| ||
Oh, I wasn't posting working code, just the relevent parts that demonstrate how Object/Handle are used. For the code to actual run, you'd need to define the type foo. |
| ||
Actually, I integrated the code into my game. I don't know why it doesn't work. |
| ||
Hello? |
| ||
I think it is something else, because the example seems to work:Type foo Field f$ End Type my_type.foo = New foo my_type\f$ = "hello" type_ID = Handle(my_type) this_type.foo = Object.foo(type_ID) Print this_type\f$ WaitKey() End |
| ||
What line of the code causes the error? Without seeing the source, we can't really guess what's going wrong. |
| ||
Here (I found that one problem was that I forgot the second line): If CountCollisions(soldier2)>0 entity=EntityCollided(soldier2,1) any_weapon.weapon=Object.weapon(EntityName(entity)) HideEntity any_weapon\inactive_model On the fourth line, I get the classic "Entity does not exist error". This dissappears when I add: If entity=True after the second line, but then no commands are executed after that. While the program functions normally after that, I'm back to where I started.:( P.S., all this code is in functions, and creating and using the weapons are in two different functions, but all the variables, including the types are global. By the way how do you insert those code pieces? |
| ||
Use: entity=CollisionEntity(soldier, 1)instead. To insert code pieces, place a text between 'code tags' You can find the tags here: http://www.blitzbasic.com/faq/faq_entry.php?id=2 |
| ||
How to look like an idiot: Step 1: Using an example from a book, try to use the code to program a shooting game. Miss several lines of code. Step 2: Check the code on the last page numerous times while forgetting to check the code on the previous page. Step 3: Post your question online to ask for help while hinting at the problem being a piece of code that functions perfectly. Involve five other people in a forum trying to find out what's wrong. Step 4: Try every suggestion without success and keep trying to find the answer from the wrong piece of code. Finnaly discover the lines of code you miss, which happen to be some of the most important parts. Step 5: Post he newly discovered code when it is asked for. Try to solve the nagging "Entity does not exist error" by inserting the code If entity=True. Solve the "Illegal type conversion error" by deleting the new code. Step 6: Repeat step five dozens of times with different methods to try to elliminate the errors. step 7: Discover that the problem is that when the soldier touches the ground in the building, the entity no longer has a name. Solution: change If entity=True to If entity<>Null Thanks for the help guyes! ;) |
| ||
lol |