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 / My function

Author
Message
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 2nd Mar 2008 17:54
Hai! I just created a small function to use in my game, and it's not working, I've checked to see if I'm calling it correctly, and I am. The function is supposed to check if the player object is within a certain position, then place him in a certain point.


There is my code, don't complain about my indentation please, I have not done any yet.

Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 2nd Mar 2008 19:09


the problem is in the end command: it can't finish the function!!!!! i don't know how to fix that though as depending on how your program works, the are many method to fix that.

Your signature has been erased by a mod. Reduce the size!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd Mar 2008 20:44
Quote: "The function is supposed to check if the player object is within a certain position, then place him in a certain point."


Then which bit does the repositioning? If you simply read your function you will see that it can't do that because you've written nothing to do it. You simply end the program.

Quote: "don't complain about my indentation please, I have not done any yet."


You joined nearly 3 years ago!!! What's your excuse?

TDK_Man

Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 2nd Mar 2008 22:46
Sorry, to make sure it was not just the positioning code failing on me I put end in there instead. I usually don't indent until I finish the block of code I am working on.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd Mar 2008 23:20
OK, so all you need to do is replace the end with the Position Object command then update the Pacman_posX# and Pacman_posZ# variables so they hold the values of the object in it's new position.

TDK_Man

Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 2nd Mar 2008 23:43
No luck, I have changed the code and put the character position check straight in the function, and it won't work. There is more to the loop, I'm just showing how I call it.



Paul08
17
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 3rd Mar 2008 00:11
cant you just forget this function and do a
set object collision on ?!
and then use dbasics inbuilt collision methods?
might just be a waste of space having this code?

Paul
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 3rd Mar 2008 00:17
This has nothing to do with collision.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 3rd Mar 2008 01:56
Quote: "I usually don't indent until I finish the block of code I am working on."

so you make it difficult for yourself, then when you finally have it working you indent it so its easy for us to read?

it seems to me that the function is supposed to work like this:
Pac man goes into a special zone (which I'm guessing is some sort of teleport thing) if he remains in the zone for a time (a very short time) he will be teleported to a new level.

Is that right?

It is a very strange piece of code

Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 3rd Mar 2008 02:37
When pacman nears a corner or T split in which he can turn, to make it so the player doesn't have to time it perfectly to make it through the hole, pacman is position it the correct place.

KISTech
17
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 3rd Mar 2008 03:18
So what I'm seeing is,

If posX# > -30 and posX# < 30 and posZ# > 30 and posZ# < -40

The first part of this might be ok, because your X value needs to be between -30 and 30. The Z value however you are testing if it's bigger than 30, but it has to be less than -40. I think maybe you have the < and > backwards for the Z position.


Don't think, just code.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Mar 2008 17:51 Edited at: 4th Mar 2008 18:17
To avoid all that I would store the inputs and...
hang on I've never made pacman so I'll try this out
[edit]
I messed it up, but basically what I'd do is round pacman's position to the nearest square and check if a change of direction would lead him to a path square, then if it does position him in the centre of the current square and change his direction.

BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 4th Mar 2008 22:29 Edited at: 4th Mar 2008 22:30
Another way to calculate the distance from the exact location could be to subtract his position from the ideal location (corner). Then take the absolute value of that and see if it is less than your tolerance values.

For instance:
*note that the cornerx#,cornery#,and cornerz# values are the x,y, and z values of the intersection, respectively
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 4th Mar 2008 23:01
I figured it out awhile a go. I then needed to find out how to keep everything separate even though it's the same function, and viola! My first use for an array.

Login to post a reply

Server time is: 2025-06-04 02:02:18
Your offset time is: 2025-06-04 02:02:18