Post Reply 
Possible Unit Comparison bug?
01-09-2014, 02:12 AM
Post: #1
Possible Unit Comparison bug?
Hey, I was trying to figure out how to program a key to behave differently with a short press and a long press, and came across something that I suspect is a bug.

Code:
KEY K_7()
BEGIN
LOCAL time;
time:=TIME(KeyTimer(32));
IF time<0.5_s THEN
  RETURN "7";
ELSE
  RETURN "It worked!";  
END;
END;

EXPORT KeyTimer(key)
BEGIN
WHILE ISKEYDOWN(key) DO
END;
END;

Simple as that is, it simply would not work until I did this:

Code:
time:=TIME(KeyTimer(32))/1_s;
IF time<0.5 THEN

This despite the fact that comparatives seem to work just fine on units in the Home screen. Is this a bug, or do I need to do something to prep the unit object in the first bit of code?

Also, not a bug but something worth knowing: I originally tried to use GETKEY in place of the key number of 32, but it didn't work. The KEY function must use GETKEY to return the key number, so when you do it again you get -1.

P.S. I eventually redid the whole thing using TICKS rather than TIME, but I still think the potential bug is worth mentioning.
Find all posts by this user
Quote this message in a reply
01-09-2014, 03:37 PM
Post: #2
RE: Possible Unit Comparison bug?
Thanks. I'm not sure either, but I've marked it down for examination.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)