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 / For/Next loops; please tell me I'm being stupid...

Author
Message
LordMaud
19
Years of Service
User Offline
Joined: 30th Jun 2005
Location:
Posted: 27th Jun 2006 17:14
First of all, Hi!

Now, I'd put myself one level higher than complete n00b, but I'm completely stumped by this.

This bit of code is meant to allow the player to interact with NPCs ((potentially) objects 1000-1999) using the mouse (object 10):



If you click when MouseState=1 then you walk over to the location of the object number of PlayerSelect.

Problem is, it only does it for object 1000, or whatever the first object it finds between 1000 and 1999.

It's probably something really trivial, so please feel free to demote me to newbie again.

Any help greatly apreciated
UFO
19
Years of Service
User Offline
Joined: 11th Oct 2005
Location:
Posted: 27th Jun 2006 19:31
Its the exit command. After the
Mousestate=1
and
Playerselect=X,
it leaves the whole for-next loop. You don't want that, because you want the other objects to work too. Just get rid of the exit and it should work.

Hope it helps

LordMaud
19
Years of Service
User Offline
Joined: 30th Jun 2005
Location:
Posted: 27th Jun 2006 19:40
Hmmm... the exit bit is only called if the mouse (Object 10) collides with the NPC (X), and as the mouse could only ever collide with one NPC at a time, it seemed pointless to let it continue checking after one had been detected.

And, as I expected, taking it out doesn't solve it.



Lord Maud
Mr X
19
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 27th Jun 2006 20:32 Edited at: 27th Jun 2006 20:51
I tested your code, and it seem to work for me. But there are one difference. I stored all the object numbers in an array, and then moved along it in the FOR-NEXT loop that controls the player movement. Here is my code:
. Hope it will help you.

EDIT:

Forgot to mention how to control everything. You control the camera whith the arrowkeys, and the "mouse" with the mouse. You press the right mousebutton to go to the "mouse", and space to position both the camera and the "mouse" at the player. If you can select one of the boxes, a red circle will apear around the "mouse", and then you select that box by clicking at the left mousebutton.
LordMaud
19
Years of Service
User Offline
Joined: 30th Jun 2005
Location:
Posted: 29th Jun 2006 21:18
Hey, cheers for your help, great idea about the arrays: NPC(1) and Building(1) is easier then remembering object 1000, object 5000 etc, so thanks for that! But it sadly didn't solve the problem:

I investigated further with this:


And found that the "if object exist" check works fine.

When the mouse (object 10) collides with the first object found by the for/next loop (object 1000 or NPC(1)), it prints "1" and "2", implying that it thinks that it has / has some how collided with both objects NPC(1) (1000) and NPC(2) (1001).

The same thing happens if I break the For/Next loop into separate statements(
)

This is far too good for me. Again, anyone with a deeper understanding whocan explain why this is would be greatly apreciated

Jack

(Oh, and I have DB classic, by the way.)

Login to post a reply

Server time is: 2024-11-26 17:44:17
Your offset time is: 2024-11-26 17:44:17