0
votes

I just started learning lua and run into a strange problem. The following code...

local xx = 100
vertices0 = {xx, xx}
vertices1 = {xx−5, xx-5}

results in...

an array containing (100,100) for vertices0 (as expected) but in an array containing (nil, 95)for vertices1.

I really dont understand what is causing the nil to appear. I expected to get an array with (95,95).

I checked the documentation and tried to google the problem. But was not able to solve this problem.

Btw - I'm using love2d but "regular" lua seeems to cause the same behaviour.

1
You're using Unicode minus sign character U+2212 instead of ASCII minus signEgor Skriptunoff
You nailed it! Thank you very much for this hint!Paraglider0815

1 Answers

2
votes

xx−5 is not using - but , lua treats as part of a identifier so xx−5 is a separate identifier rather than the desired subtraction operation xx - 5

local xx = 100
local xx−5 = 100
vertices0 = {xx, xx}
vertices1 = {xx−5, xx-5}
  
print(vertices1[1])

This appears to work in 5.1, but not later version of lua. additionally an issue like this can be seen easier if you place a space around an operator and it's operands, which does tend to be a good style choice for readability.

vertices1 = {xx − 5, xx - 5}

Also if you have syntax highlighting than you can notice the improper char does not get highlighted properly.