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 / Question about Functions

Author
Message
Captain IceT
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Boat Murdered, and Im still laughing!
Posted: 21st Oct 2008 20:22
Hello all!
I have actually been a member of this forum before, but I put down DBPro to work on other things, and I am now coming back. I have run into a bit of a problem using functions in my program.

The following works, I am able to use WASD to control the camera, smoothly moving by increments of 50, and turning 90 degrees.


However, when I move the bulk of the control code to a function, called Player_Move(), It stops turning by 90 degrees, and moving in increments of 50, it seems like it cycles within my function until the timers have counted down before exiting. Any ideas how to prevent this?

Here is the code with the function:
Captain IceT
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Boat Murdered, and Im still laughing!
Posted: 21st Oct 2008 23:13
I think I answered my own question.

Turns out the variables I'm using have to be Global, as I think that it does not keep the value when I exit the function...

does that sound right?
Captain IceT
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Boat Murdered, and Im still laughing!
Posted: 21st Oct 2008 23:19
Well it seems to be working better, but the camera seems to be turning further than 90 degrees now...

Here's my updated code:
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Oct 2008 23:27
That's exactly right.

By default, all variables declared outside a function are not available within a function, and all variables declared within a function are local to that function and are not available outside of it.



I won't go into arrays, but just assume for now that they are automatically global. (Their behaviour seems different in 7.1 but that may have occurred in an earlier release)

Captain IceT
16
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Boat Murdered, and Im still laughing!
Posted: 21st Oct 2008 23:34
Nevermind, I will quit bothering you good people with simple errors.

(I forgot one of the variables when I started declaring as global. If you add GLOBAL Command AS INTEGER, it works fine.)

Login to post a reply

Server time is: 2024-11-25 16:52:34
Your offset time is: 2024-11-25 16:52:34