Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / limb does not exist error

Author
Message
Thomas85
11
Years of Service
User Offline
Joined: 29th Apr 2012
Location:
Posted: 29th Apr 2012 08:11
Hi yall! I'm new to the forums and to DarkBasic, so please go easy on my code...

I'm trying to create a builder-type simulation where the player can add buildings to a sphere that's in constant y-axis rotation. The best way I figured I could do this was to create an array of limbs that the buildings glue to, but I get an odd error consistently with limb number 41. Here's my code:



As you can see from my if then in the loop, it deffo see's that limb 41 exists, but then when you try to glue to limb 41, DB decides it doesn't anymore. I tried to create the limb blocks separately in the hopes that might do the trick, but to no avail. Please help DB gooroos!

thanks!
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Apr 2012 12:12
@Thomas85

Hello and welcome!

I'm not at a computer with DB on it at the moment, but eyeballing your code, I think you are getting a huge increase in x values that goes beyond your limb count in code you have near the end:



The culprit, I would guess, is If Spacekey()=1 ... x=x+1 .

Because you could be pressing the spacekey longer than you anticipate before you release it, x may run up quite high. And since you are using x as the variable for the limb number, you will most likely be exceding your limb count.

2 things you need to do:

1. Make sure that the spacekey() press only registers once per press and release and doesn't key repeat.

2. Have a limit on x that stops at 90 or resets to 1 when 90 is reached.

The spacekey thing can be handled with a comparision of it's last state and current state:



The limit can be handled easily as well and incorporated into the spacekey code:



Enjoy your day.
Thomas85
11
Years of Service
User Offline
Joined: 29th Apr 2012
Location:
Posted: 29th Apr 2012 16:03
That does make sense, but I can watch my program add the limbs as I push the spacekey, and even holding it down it consistently stops at 40. If the x value was running too high, wouldn't it still add a limb to all the previous x values? I will try your code anyway, but I really only added that part as a test bed to see where the bug was. I didn't put it in my snippet (STOOPID!!!) but right before the loop begins I have a routine that chooses a random number between 1 and 90, then chooses that limb number to glue object 3 to. Unfortunately, I'm not on a DB computer either, but the code looks something like this:

random:
r=rnd(89)+1
if limb exist(1,r)=1
glue object to limb 3,1,r
else
goto random
endif

there's other code in there that handles the rotation of the object, but that's the part that I remember where DB is having trouble. As you can see, my code has something that handles the possibility of the limb not existing, so the fact that it still returning a "limb does not exist" error makes no sense. I appreciate the help Latch!
Thomas85
11
Years of Service
User Offline
Joined: 29th Apr 2012
Location:
Posted: 30th Apr 2012 02:38
Ok, so I kinda solved the problem. Instead of trying to make the program glue the object to random limb 1 to 90, I duplicated the sphere that the limbs attach to to make three spheres occupying the same location in 3D space, then created 30 limbs on each set at the proper offsets to give the appearance of one sphere with 90 limbs. After making my code a little hairier, I finally got my program to behave like I want it to. So until the next hurdle, thanks everyone!

Here's what my code looks like now in case anyone is interested...

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Apr 2012 10:02 Edited at: 30th Apr 2012 10:13
Well, it seems you have stumbled upon a little known if not unknown limitation in the highest limb number that can be glued to. It seems one can only glue objects to limbs 0-31 . Anything higher and the LIMB DOES NOT EXIST MESSAGE shows up. Even when the limbs do indeed exist.

A quick test:



This works but if you change glue object to limb 2,1,31 to a higher limb (32 or above) the error will occur.

Thanks for uncovering this!

As it is, I always try and avoid using glue object to limb unless it's simple code, or there really is no other way to get what I want.

If you don't need to query the limb's Z angle, you can use the limb position and limb angle commands to place your object as if it was glued.

An alternative to gluing besides positioning, could be to change the mesh of the limb into whatever shape it needs to be at any given time.

CHANGE MESH obj,limb,mesh
SHOW LIMB obj,limb

Enjoy your day.

Login to post a reply

Server time is: 2024-04-19 16:17:41
Your offset time is: 2024-04-19 16:17:41