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 / Problem with a simple counter

Author
Message
Gothicjawa
13
Years of Service
User Offline
Joined: 26th Sep 2012
Location:
Posted: 26th Sep 2012 13:55
Hey peeps, im very new to programming and was wondering if anyone could help me out a little. I am in the early process of coding a fuel system for a space ship, The code I have written works very well, the only problem is the counter I have declared for the Fuel doesn't start at 100. I bet its something very simple hehe. here's the code Im using and Im calling the function in the init loop. Any help will be much appreciated.

Global FCounter = 100 as float

Function Fuel()
if keystate(17)
FCounter = Fcounter -0.001
endif
set cursor 550,200
print "Fuel: ",FCounter
EndFunction
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 26th Sep 2012 15:22 Edited at: 26th Sep 2012 15:23
Hello and you were pretty close, just got the variable type declaration the wrong way round, so:

Global FCounter as float = 100.0

Just note that not all things can be setup this way, like '... float = <function return>' will not work and will remain 0, in which case:

Global FCounter as float
FCounter = ...
Gothicjawa
13
Years of Service
User Offline
Joined: 26th Sep 2012
Location:
Posted: 26th Sep 2012 15:42
Hehe thankyou for the swift reply . Ahh i see, as im said im very new to programming, I attempted it when i was younger but was too much for me so i went down the graphical designer route, now though ive been wantingto learn more about since my friend showed that programming is alot simpler when someone explains stuff to you . but again thank you for your help and btw I like Naruto too hehe.
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 2nd Oct 2012 20:46
Here's a bit simpler approach for a float:



D.D.

Login to post a reply

Server time is: 2026-07-07 19:11:00
Your offset time is: 2026-07-07 19:11:00