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 Professional Discussion / function not returning result

Author
Message
pictionaryjr
17
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 29th Mar 2011 03:46
This is my function for a center text button. It seems to work perfectly with returning if state=0 or state=1 or state=2, but when it comes to returning 3 it won't work and when i run over the code. everything seems right and it runs in dbc. I'm confused again



Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 29th Mar 2011 04:51
It seems you're relying upon the state some local variables between calls. In DB classic locals are static, so they retain their value between successive function calls, this is not the case in DBpro. Each time you call the function all the locals variables have a initial state of zero or empty for strings. So the variable clicked will always be zero in Dbpro.

To see the difference try this in both.




I suspect you can solve your problem by making "clicked" (and any other values that need to be retained as globals (be they variables or stored in a type structure).

pictionaryjr
17
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 30th Mar 2011 21:27
thanks for the help Kevin. It explains why people put their variables as globals at the beginning of the program

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 31st Mar 2011 02:57 Edited at: 31st Mar 2011 03:00
For things like input, I tend to avoid polling the the mouse() keystates through out the program. While they can be surprising hogs at times, this mainly solves a common logic problem where the user can select multiple things during one refresh. Which occurs because the mouse can have moved between calls.

Preferring to grab the key & mouse states (X,y,buttons) into a type at the start of each refresh.

(PB formatted code, change to suit)


So the states are global but are stored in a type structure.

Login to post a reply

Server time is: 2026-07-11 14:57:05
Your offset time is: 2026-07-11 14:57:05