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

Author
Message
Stora tomtefar
20
Years of Service
User Offline
Joined: 15th Mar 2005
Location: Göteborg, Sweden
Posted: 5th Mar 2006 13:34
Hellu ye all.

Well, I'm experimenting with functions and Since I just just gosub's before, I'm not so familiar with the whole idea with functions, although I guess that functions and gosub's does have one or two things in common.

I tried to use this quite simple code in my program:



I want the value namned 'funktion#' to be increased by 10 everytime the screen is updated, but it's only increased once, constantly showing the value of 10 one the screen.
So, my guess was, and is, that I made something wrong within the function command. Anybody knows what this might be? Could you please try to explain with simple words how a function really works, please?
Thanks!

www.godhatessweden.com

Good laughter!
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 5th Mar 2006 15:55
Well, the parameter you pass through, is always 0.

Funktion(Funktion#(=0.0)) will give you therefor: 10.0

If you want it to be constantly increased, then you should put the returned value, in the current one. Like this:

Funktion# = Funktion(Function#)

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Halo Man
19
Years of Service
User Offline
Joined: 5th Nov 2005
Location:
Posted: 5th Mar 2006 15:57
I think you need to add:



Then you can refresh the screen

Also, add 'set text opaque' right before the text in function funktion

Current working on Online Paintball.
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 5th Mar 2006 15:58
Try this,


do

Funktion#=Funktion(Funktion#)

sync
loop


So the variable Funktion# is being passed into the function, and the function is returning the new result

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 5th Mar 2006 22:12
Since it doesn't look like that number will ever have a decimal point it doesn't need to be a float. Also the variables in the function don't have to be the same name as the variables you're using outside of the function.




Login to post a reply

Server time is: 2025-05-23 09:24:35
Your offset time is: 2025-05-23 09:24:35