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.

Newcomers DBPro Corner / Orbiting a Moon around a Planet. Function Error.

Author
Message
Hanne
12
Years of Service
User Offline
Joined: 26th Apr 2012
Location:
Posted: 26th Apr 2012 19:18 Edited at: 26th Apr 2012 21:23
Hey guys. I've got a strange Problem.

I tried to work with a tutorial on youtube, which got the same title as my topic

My program works fine until i try to use a function for moving the planet around the sun.

the working sourcecode looks like this (without using the function "RotateAroundSun"):



Okay. When i use the function f.e



The Planets get generated but dont move.
What am i doing wrong?

Greetings from Germany and thanks in advance.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 27th Apr 2012 04:45 Edited at: 27th Apr 2012 04:51
Make grad global and move xpos and ypos in to the function. Also change the function to RotateAroundSun(PlanetNumber,radius as float,speed as float)

Hanne
12
Years of Service
User Offline
Joined: 26th Apr 2012
Location:
Posted: 27th Apr 2012 20:32
Thanks!
That helped me out.

It worked already when i took xpos and ypos into the function.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 28th Apr 2012 13:13 Edited at: 28th Apr 2012 13:20
The reason you have to make grad a global is that variables only works local until declared as a global. Like you can have two functions, lets call them Function(1) and Function(2)



The two grads works with different numbers inside the two functions, hence they only work local.

I would advise you to read this post about functions, it is great reading! http://forum.thegamecreators.com/?m=forum_view&t=96040&b=7

EDIT: Forget about that post, it is for DarkBASIC Classic, I just assumed it was for DBPro because it was in DBPro Newcomers. I think local variables are destructive in DBPro, so when you exit your function any local variable is destroyed or "forgotten" and the function will not remember your "grad" variable next time it calls the function. I hope this was not too confusing :-P

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Hanne
12
Years of Service
User Offline
Joined: 26th Apr 2012
Location:
Posted: 1st May 2012 23:24
Not confusing i understand that.
I just didnt know that i have to set them global manually.

I just grew up with pascal and c# where i didnt need to set them "public" when the variable was in one and the same unit.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 5th May 2012 22:56
Okay, and arrays are automatically global

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

Login to post a reply

Server time is: 2024-05-17 11:48:37
Your offset time is: 2024-05-17 11:48:37