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 / function help

Author
Message
Axelman
21
Years of Service
User Offline
Joined: 18th Oct 2003
Location: Parallel Universe
Posted: 25th Nov 2003 05:53
i need help with functions! when ever i make a function
e.g



it comes up with an error saying "program ran into function declaration". i thought programs were supposed to do that!
it does't always happen with that function, when iwas trying to make a function for the camera in my game it would always pop up with that as an error.
when i use the code for other games (like the code for limit rush in the binary moon tutorials) the error doesn't show up.

please help, forward in advance

Axel Waz `Ere
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 25th Nov 2003 06:09
Ok, what you have to do is put the function out side of your main loop. Also, the way you have the function set up, it is wrong.

The example you gave above:


In that, you cannot use print a as teh function name, because, 1, it has a space, which is illegal, and 2, it doesn't have the "brackets" at the end which define it as a function.

Try changing it to this:


Then stick that function out side of your main loop. If the command Function gets read fromwithin your main code, it will produce the error you described.

Here is how you do it:


If you made it:


It would produce that error, because you are tryign to declare the function on the loop, whcih you are not allowed to do.

You must always declare the function away from any other code that is to be executed, then call the function from within the loop.

In this case, the function was declared after the loop withthe Function and EndFunction commands, and was called during the loop by simply putting in the function name print_a()


The "brackets" at the end allow you to pass the functions values, ie:



In that above example, the string "Hello World" would be passed to the function, and the function would store it in the variable a$ ( since that is the corresponding variable in the "brackets" )


Here is what the DBPro help files have to say about functions:



Hope I Helped...


PS I'm not too sure if i should have posted that help file, because it is from the DBPro help files, but i figured since it's from the trial version, hence, the free version, then it was ok.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Axelman
21
Years of Service
User Offline
Joined: 18th Oct 2003
Location: Parallel Universe
Posted: 25th Nov 2003 07:02
alright this is exactly what i did. i

1.opened darkbasic
2.made new poject file "function help"
3.typed in


if i do it like this it doesn't print anything

if i do it like this so the function is before the loop...


it does the error thing and if i do it like this with no loop


it does the error thing too!

i'm so frustrated because i can't do the camera for my game which is really important.

i'm really p***ed off!
hope you can understand me jess (and anyone else)

thanks ifyou can help

Axel Waz `Ere
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 25th Nov 2003 08:18
alright, try changing


to this



in order to call a fuction, you have to write it out EXACTLY how you defined it. so function print_a$() could not be called by typing print a$

everything inside of the brackets (), are varables or values PASSED into the function.
so:


"hello world" would be passed to the function under the varable 'a$'

play around with it, you'll get it. i didnt understand functions until i played with it.

=<=Pudgie Wars=>=
Game engine: 20% = Models: 25% = Textures: 1% = Sounds/Music: 0%
Axelman
21
Years of Service
User Offline
Joined: 18th Oct 2003
Location: Parallel Universe
Posted: 25th Nov 2003 11:22
thanks man you are a hero.
thanks for trying to help jess, you do enough help on these forums.

onward from this forum/thread, i hereby am going to try to stop posting stupid questions about darkbasic and am actually going to figure it out my self
thanks all!

Axel Waz `Ere
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 25th Nov 2003 11:44
Hmm, what Darwin posted is also incorrect.

using:


Won't work. you need the brackets at the end of the functino call in teh loop. such as:



Hope I Helped...

PS i only help cos im just always here, and i figure, people helped me, so ill return the favour...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Axelman
21
Years of Service
User Offline
Joined: 18th Oct 2003
Location: Parallel Universe
Posted: 25th Nov 2003 12:28 Edited at: 25th Nov 2003 12:29
jess ure like the [i][/i]GURU and i kinda figured out that you had to have the brackets their already, i'm not that stupid

ps thanks again darwin

Axel Waz `Ere
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 25th Nov 2003 12:31
Quote: "jess ure like the GURU"


Shut up man, your giving me a big head... lol...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 26th Nov 2003 00:18
yeah, i knew that, i just didnt post it. i was really tired. sorry if i confused anyone

=<=Pudgie Wars=>=
Game engine: 20% = Models: 25% = Textures: 1% = Sounds/Music: 0%
Axelman
21
Years of Service
User Offline
Joined: 18th Oct 2003
Location: Parallel Universe
Posted: 26th Nov 2003 06:54
don't worry about it darwin i knew what you ment

Axel Waz `Ere

Login to post a reply

Server time is: 2025-05-21 16:19:08
Your offset time is: 2025-05-21 16:19:08