Jump to content
  • Advertisement
Sign in to follow this  
TheCoderGuy

Lua Program isn't working

This topic is 670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm trying to code a simple text fight using Lua, but I keep getting the same error even though I'm doing what it's saying.
Here's the code:
 
print 'A zombie appears. What do you do?'
os.execute("sleep 5")
if sleep = 0 then
  print 'The zombie scratches you and you die.'
Attack = io.read()
print 'The zombie is injured.'
 
It should make it so if you wait five seconds then you die, but here's the error message that shows up: [string "print 'A zombie appears. What do you do?'..."]:3: 'then' expected near '='
I'm not sure what I'm doing wrong.. Can anyone help with this?

Share this post


Link to post
Share on other sites
Advertisement

Wait, nope I got it
 

 

My general feeling is that you should explain what you found out and fixed. There's is nothing more infuriating in the world than having a problem, Googling it, finding someone asking about the same or a similar problem, then seeing a "nevermind fixed" comment with no explanation. :)

Share this post


Link to post
Share on other sites

My general feeling is that you should explain what you found out and fixed.

I agree, it could help future others. 

Share this post


Link to post
Share on other sites

if sleep = 0 then
 

Problem is here. You're not checking 'sleep' for zero, you're assigning zero to it.

That's a violation of Lua syntax. 'If' expects expression, not the statement.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!