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 / Cannot move objects at variable speeds.

Author
Message
Interplanetary Funk
16
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 1st May 2010 20:17
I've run into another snag while teaching myself DarkBasic, this time I'm trying to make an object accelerate when the up key is pressed. however, when I do press it nothing happens, it just stays still. Here's my code for the acceleration:


the acceleration variable is set to a value of 70 (and is not changed anywhere in the program after being initialized) and speed is initialized at a value of 0.

the thing is, when I tell the object to move at a fixed value, e.g. "move object 2, 30" it will move fine, it's only when I try to use a variable it won't.

Massively confused as to why this is happening, I've just upgraded to v1.075 if that might be causing this otherwise I'm drawing blanks. any help would be great =)
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 1st May 2010 20:21
You need to use floats for starts, and as those variables are in a function, you need to make them global.

Rawwrr. Sig Fail.
Newcastle is awesome
Interplanetary Funk
16
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 1st May 2010 22:18
The variables are global, and changing them to floats doesn't do anything =(
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 1st May 2010 23:39
Can I see the rest of your code?

Rawwrr. Sig Fail.
Newcastle is awesome
Interplanetary Funk
16
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 1st May 2010 23:50
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 1st May 2010 23:54 Edited at: 2nd May 2010 00:00
if there isn't any other code then with the above bit if you do nothing then the object should start moving backwards, however if it was doing that you would not be posting about how to make it move.

qiuck look try knocking out this line and see what it does.



Dark Physics makes any hot drink go cold.
Interplanetary Funk
16
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 2nd May 2010 00:28
Nope, makes no changes to anything, just doesn't make the object fall. =( (and that's my entire code for it atm)
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 2nd May 2010 01:32
Quote: "The variables are global, and changing them to floats doesn't do anything =( "


No they aren't To make them global you have to write "global" when you declare them. So this:



Should be this:
Garion
18
Years of Service
User Offline
Joined: 7th Dec 2007
Location: Poland
Posted: 2nd May 2010 01:38 Edited at: 2nd May 2010 01:40
for functions you need to define the variables as global... like this, Mad Nightmare has mentioned it but I can't see it in your code.



By the way you can just use camera 0, the default one And remember to position it above/next to the object and point camera at it or you won't see anything.

Edit:
Oops, too slow
Interplanetary Funk
16
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 2nd May 2010 01:46
Oh, I didn't know there was a global keyword, I presumed global variables worked as they do in c++ (the only language I actually know a bit about) anyway, it now works, so thank you very much =)

also, I know I can use the default camera, I just find it makes my code clearer to understand if I declare a camera 1 =)
Garion
18
Years of Service
User Offline
Joined: 7th Dec 2007
Location: Poland
Posted: 2nd May 2010 01:53
Cool, keep coding
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd May 2010 17:06 Edited at: 2nd May 2010 17:08
You wouldn't have that problem if you used a subroutine instead of a function (a void function in C++ terms I suppose).

Functions have a purpose - and IMHO the code you have in accelerate() and gravity() doesn't really warrant being in a function.

TDK

Login to post a reply

Server time is: 2026-07-26 04:27:16
Your offset time is: 2026-07-26 04:27:16