Value not changing?

BlitzPlus Forums/BlitzPlus Beginners Area/Value not changing?

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?

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


Nada.

BTW all my other scancodes work fine

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.

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.

It doesn't work in my graphics mode game.

I'd have to see your code if I was to figure anything out for you. Post it if you like; otherwise, good luck!

worked fine for me, win XP, blitz plus v1.44

		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.

There is a hint in this thread that can hopefully help you.

D'oh! I think there was a code error (different variables).
I am testing my game right now.

Tested and nischt response.

What could be causing this

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.

This all sounded familiar. Didn't someone comment on this a few years ago?

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