Value not changing?

BlitzPlus Forums/BlitzPlus Beginners Area/Value not changing?

acolite246(Posted 2009) [#1]
Hey-
I am having a problem with my program, shown simplified below:
Global runspeed = 10
Global xVel = 0
Global yVel = 0
While Not KeyHit(1)
	If KeyDown(17) And xVel < runSpeed Then xVel = xVel+1
	If KeyDown(31) And xVel > (0-runSpeed) Then xVel = xVel-1
	If KeyDown(30) And yVel > (0-runSpeed) Then yVel = yVel-1
	If KeyDown(32) And yVel < runSpeed Then yVel = yVel+1
Print xVel+","+yVel
Delay 1000
Wend

I have tried the code with both KeyHit and KeyDown
When I run the above code, I get

0,0
0,0
0,0


ad infinitum.

How can I fix this?


Matty(Posted 2009) [#2]
I can't see anything wrong with that code, but the delay may be causing problems - as a quick test how about trying:

Global runspeed = 10
Global xVel = 0
Global yVel = 0
While Not KeyHit(1)
	If KeyDown(17) And xVel < runSpeed Then xVel = xVel+1
	If KeyDown(31) And xVel > (0-runSpeed) Then xVel = xVel-1
	If KeyDown(30) And yVel > (0-runSpeed) Then yVel = yVel-1
	If KeyDown(32) And yVel < runSpeed Then yVel = yVel+1
if xVel<>0 or yVel<>0 then Print xVel+","+yVel
Wend



acolite246(Posted 2009) [#3]
Nada.

BTW all my other scancodes work fine


epiblitikos(Posted 2009) [#4]
Well, if it's any comfort, your code performs the same weird result on my computer. I'll be working on this one, so post if you solve it.


epiblitikos(Posted 2009) [#5]
Global runspeed = 10
Global xVel = 0
Global yVel = 0

Graphics 640, 480, 0, 2

	SetBuffer BackBuffer()
	Color 255, 255, 255
	
	While Not KeyHit(1)
		Cls
		If KeyDown(17) And xVel < runSpeed Then xVel = xVel+1
		If KeyDown(31) And xVel > (0-runSpeed) Then xVel = xVel-1
		If KeyDown(30) And yVel > (0-runSpeed) Then yVel = yVel-1
		If KeyDown(32) And yVel < runSpeed Then yVel = yVel+1
		Text 0, 0, (Str xVel) + ","+ (Str yVel)
		Delay 100
		Flip
	Wend
EndGraphics


I got it to work inside a graphics mode. I take it that your are creating player input which would be called with the graphics mode running, so I am assuming this will be a reasonable work-around for you. It's awfully peculiar that it won't work in a console program--if I find something in the bug reports, I'll post it here.


acolite246(Posted 2009) [#6]
It doesn't work in my graphics mode game.


epiblitikos(Posted 2009) [#7]
I'd have to see your code if I was to figure anything out for you. Post it if you like; otherwise, good luck!


Snarkbait(Posted 2009) [#8]
worked fine for me, win XP, blitz plus v1.44


acolite246(Posted 2009) [#9]
		If KeyDown(17) And xVel < runSpeed Then xVel = xVel+1
		If KeyDown(31) And xVel > (0-runSpeed) Then xVel = xVel-1
		If KeyDown(30) And yVel > (0-runSpeed) Then yVel = yVel-1
		If KeyDown(32) And yVel < runSpeed Then yVel = yVel+1

is the exact code written in my game. I don't my game in front of me (I'm using a different computer) but I will post it.


skidracer(Posted 2009) [#10]
There is a hint in this thread that can hopefully help you.


acolite246(Posted 2009) [#11]
D'oh! I think there was a code error (different variables).
I am testing my game right now.


acolite246(Posted 2009) [#12]
Tested and nischt response.

What could be causing this


Gabriel(Posted 2009) [#13]
If you had read Skidracer's reply above, you would know what was causing it.

Clue: The expressions are not being evaluated in the order you think they are, and Skidracer's link tells you why and how to fix it.


Floyd(Posted 2009) [#14]
This all sounded familiar. Didn't someone comment on this a few years ago?

Sure enough, it was me. I had completely forgotten.