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.

Newcomers DBPro Corner / Help with a gosub

Author
Message
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 23rd Feb 2005 04:05 Edited at: 23rd Feb 2005 05:01
I think the gosub causes the problem.

I have this code



But when i run it, the game just closes before displaying anything.

Thanks in advance.

P.S It worked before i added that bit of code.
TravisP
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location: Behind you, with a knife!
Posted: 23rd Feb 2005 04:11

Change the GoSub to Goto. GoSubs are suppose to return.

Note: The above I didn't say, your just crazy.

Not a ripoff of The Twilight Zone
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 23rd Feb 2005 04:42
That makes the program never load
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd Feb 2005 04:57
put back gosub

at the end of the sub code put Return

Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 23rd Feb 2005 04:59
Well what are you actualy trying to acheive? as that code is breaking so many coding rules i nearly cried ! (your last next didnt have an 'x' after it, you never gosub into loops like that and especialy not out of one nested loop into another loop...oh god ive gone crosseyed!)

Ok so lets take it from the top, what are you trying to achieve? and then we can help!
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 23rd Feb 2005 05:03
@CattleRustler That gives the same problem.

@Baggers The next x was a cut and paste error I am trying to make a code which positions 20 trees randomly around the map, none of which collide with each other.
TravisP
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location: Behind you, with a knife!
Posted: 23rd Feb 2005 05:54

This works perfectly fine with me(even with the broken code rules and all). Are you using DBPro or DBC?

Note: The above I didn't say, your just crazy.

Not a ripoff of The Twilight Zone
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 23rd Feb 2005 06:16
DBPro.

P.S next time i reply will be tomorrow evening.

Thanks in advance for the replies
Monsieur Mort
19
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 23rd Feb 2005 06:19 Edited at: 23rd Feb 2005 06:19
I haven't tested this code, but I think this should work:

What I've done is to replace your gosub bit with a while loop, and made a 'flag' called collision which equals one if the tree being placed touches another one. What happens is that each time you position a tree collision is set to zero, and then it loops through the trees already made to see if there's a collision. If there is then collision is set to zero, so the program loops back to where it says "while collision=1", another position is picked and tested and so on until a position is picked where there is no collision, so it ends teh loop. It should all work fine.

Oh, and btw I also changed your "for y = 10 to..." to loop up to x-1 instead of x. There's no need to see if object x collides with object x is there?



Why do you sink I ave zees outRAGEOUS accente?!
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 23rd Feb 2005 20:31
Ahhh now thats nicer, i can stop twitching now!
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 24th Feb 2005 00:22
I had to remove the final [endwhile] as that caused an error but if i do that, all that does for me is create 1 more tree (possibly many on top of each other?) at 0,0,0
Monsieur Mort
19
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 24th Feb 2005 03:41
oops, the final endwhile was a mistake - shouldn't have been there at all.

I should also have put a line:

collision=1

just before the start of the while loop. Like so:



Why do you sink I ave zees outRAGEOUS accente?!
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 24th Feb 2005 06:11
That leaves my computer screen black :S Nice sig btw

I may have to position all the objects manually
Monsieur Mort
19
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 24th Feb 2005 07:20
Dammit it does? I don't see why it should. Lets see... collision is automatically one... while it is one, we set collision to 0 so it exits the loop if there's no collision... we pick a position, test for collisions with objects 1 to x... if there is one, collision = 1 so it loops again... if not collision is 0 so it move onto the next tree...

No I definitely can't see why it's doing that. Anyone else see the obvious mistake?

Why do you sink I ave zees outRAGEOUS accente?!
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 25th Feb 2005 01:48
I can't see any mistakes I guess ill just position them all manually

Thanks for trying anyway
wmf
19
Years of Service
User Offline
Joined: 6th Nov 2004
Location:
Posted: 1st Mar 2005 03:47
Quote: "Oh, and btw I also changed your "for y = 10 to..." to loop up to x-1 instead of x. There's no need to see if object x collides with object x is there?"

you said you changed it but you didn't. it never stops looping. the following should work.
Monsieur Mort
19
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 1st Mar 2005 06:58
You're right I forgot to change it in the copy of the code I pasted in my post, well spotted, but why would that stop it from ever finishing the loop?

Why do you sink I ave zees outRAGEOUS accente?!
wmf
19
Years of Service
User Offline
Joined: 6th Nov 2004
Location:
Posted: 1st Mar 2005 08:54
I don't know but watching the variable x, it never changes. it stays at 11.

Login to post a reply

Server time is: 2024-09-23 13:11:18
Your offset time is: 2024-09-23 13:11:18