«I’m doing some random coding, just to improve skill, and my problem is
<I got the following code:
pos_x = math.random(0, 800)
pos_y = math.random(0, 600)
print(“Enemy pos: (”…pos_x…“,”…enemy_y…“)”)
<And the error that appears in console:
Lua: main.lua:444: attempt to call field ‘random’ (a nil value) stack traceback:
** main.lua:444: in main chuck**
«What a goose is going on? I
Hey @TheUssual, welcome to the community!
I found your Repl but please link it yourself next time.
My Lua’s a bit rusty, so I won’t be able to help you unfortunately.
Sorry for all this time, I hope you can help me now
eneny_y … should it not be pos_y?
Sometimes errors are confusing and it might refer to that
Actually, looks like this is a school assignment. We can’t give you the answer but we can point you in the right direction.
First of all,
enemy_y is undefined. Did you mistake it for a different variable?
Second of all,
math.random(0, 800) is giving an error. Check out this StackOverflow post, it may help.
Third of all, all your variables are global. It’s better practice to use local variables. You can make them local by using the keyword
Hope this helped!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.