Check out Atomic Chess, our featured variant for November, 2024.


[ Help | Earliest Comments | Latest Comments ]
[ List All Subjects of Discussion | Create New Subject of Discussion ]
[ List Earliest Comments Only For Pages | Games | Rated Pages | Rated Games | Subjects of Discussion ]

Single Comment

@ Gerd Degens[All Comments] [Add Comment or Rating]
H. G. Muller wrote on Thu, Feb 29 07:54 AM UTC in reply to Fergus Duniho from 03:07 AM:

@Fergus: OK, so it is what I thought. But it only contains values for pieces that are present; labels of pieces that are not on the board do not get value 0 associated. This makes it tricky to use.

What is the best way to test whether an associative array contains a given key? In JavaScript I would just copy array[key] to a variable, and then test if that variable is undefined.

But testing for an undefined value seems to be difficult in GAME code. In seems that variables to which you assign an undefined value disappear, and that #name for nonexisting variables evaluates to the string literal "#name". Is this guaranteed behavior? I.e., would it make sense to write

if != #name "#name":

to only process a variable when it does exist / was not assigned an undefined value?

Or can the problem be avoided by reading the value of the variable using var rather than #? Is there any guaranteed behavior for using var on a non-existing / undefined variable?

If not, it seems to be useful to have an operator (let's call it number) that would evaluate to the numerical value of its operand, but to zero if the operand was not numeric, or undefined. So that I could write something like number elem #key piececount, which would give me the expected 0 if #key was not a valid key in the piececount table.