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.

Dark GDK / you would think it would be easy to move a box

Author
Message
Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 1st Jun 2008 23:41
I dont know why im getting this problem. I have a box thats in the center of the screen, I want it to move left/right. and for some reason I cant!! its driving me insane, ive never had any torubel before:




Your signature has been erased by a mod - please reduce it to 600x120
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 2nd Jun 2008 00:07 Edited at: 2nd Jun 2008 00:09
The line:
px=dbSpriteX(1)
is undoing your increment/decrement code by assigning the current sprite X position to the variable. Move that line up, or better yet, get rid of that line altogether and set px to 320 before your loop.
kBessa
18
Years of Service
User Offline
Joined: 8th Nov 2006
Location: Manaus, Amazonas, Brazil
Posted: 2nd Jun 2008 00:13
Here "px=dbSpriteX(1);" you are attributing the sprite X position to the variable, so the "px++ and px--" are useless.

do it like this:



Try it and tell me if it works
Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 3rd Jun 2008 18:19
i got that working, but now i have another problem.

anytime i use that line my box locks in place and it refuses to move...

Your signature has been erased by a mod - please reduce it to 600x120
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 3rd Jun 2008 18:37
actually kbessa, it would proabbly be better to use

because otherwise if you press both keys, it will go left instead of nothing, which is what you would expect.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 3rd Jun 2008 21:33
Jeez, I think this guy needs to learn some basic scripting. I suggest Lua.

I AM THE ALL MIGHTY CORNHOLIO! Do you have TP for my bunghole?
Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 3rd Jun 2008 21:44 Edited at: 3rd Jun 2008 21:46
Vesper103,

something you need to understand about variables and operators.

When you are using the equals operator:

the variable on the left will be given the value of the variable on the right.
If you want to put the value of A into B, you say B=A. This is read "b equals a", and you can think of that as commanding B to match the value of A.

Not to mention the function dbSpritePosition(1) does not take a value, it gives one. In order to make the sprite take the value of "px", you must use the dbPositionSprite command, and put "px" as the X parameter. Pseudo-code:


That last line takes four values. The first one is the ID number of the sprite we want to move. The next two are X and Y respectively—I put in "px" as the x coordinate, so that it will be where you want it on the left-to-right axis. I just put in 0 as the Y coordinate, meaning the sprite will be on the top edge of the screen, because I was lazy. img is a variable holding the ID number of the image you want your sprite to be.

Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 3rd Jun 2008 21:49
Nicely explained, Image All.

I AM THE ALL MIGHTY CORNHOLIO! Do you have TP for my bunghole?
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 6th Jun 2008 22:23
That B=A example, it makes much more sense if you read it as "B is assigned the value of A." That's how I think of it, anyway. "B is equal to A" is reserved for boolean comparisons with ==.


My site, for various stuff that I make.

Login to post a reply

Server time is: 2024-11-17 17:34:18
Your offset time is: 2024-11-17 17:34:18