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 / Remember function local variables

Author
Message
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 21st Feb 2012 21:13 Edited at: 21st Feb 2012 21:39
I have this in a function, and I want the code to remember my run_once_map_camera_span_calculate = 1 variable, is the only way to declare it as global?



EDIT: Are constants declared in functions forgotten as well?

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Feb 2012 22:17 Edited at: 21st Feb 2012 22:17
Constants can't change so how can they be forgotton? Also, constants are all global anyway.

Yes, the only way is to declare it as global. You can avoid crowding the code with globals by making a UDT with all the values you need and then declaring a single global using that UDT.

[b]
Jaeg
20
Years of Service
User Offline
Joined: 16th Mar 2006
Location: Indiana
Posted: 21st Feb 2012 23:29
You could also have your function return the value of run_once_map_camera_span_calculate and store it.

Go ahead. Walk into Mordor.

Ball State University - Computer Science Major
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 25th Feb 2012 22:31
Thank you guys, it was for optimizing code and only running specific calculations once when needed. For now I will concentrate on progress in my programming of a map editor.

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...

Login to post a reply

Server time is: 2026-07-09 23:12:07
Your offset time is: 2026-07-09 23:12:07