Zach Herzer
Zach Herzer

Reputation: 31

Syntax error: player.lua:11: '=' expected near '<eof>'

I have recently been learning Lua with Love2d, so I decided to start making a simple RPG. It's quite simple. The console is where you play, and the extra window is where you can see your stats, equip items, ect. But, I have run into a problem! Whenever I run the code, I see this main.lua:15: '=' expected near 'else'

I will include the code (all 3 files) below. This is main.lua

function love.load()
love.graphics.setBackgroundColor( 255, 255, 255 )
require("player")

print("Enter your name")
pcStats.Name = io.read()

print("What class are you, " .. pcStats.Name .. "?")
pcStats.Class = io.read()

if pcStats.Class == "Ranger" then 
    os.execute("cls")
    pcInv.InvSpace = 10
    pcInv.Items.basicBow = Basic Bow
else
    print("Error: Invalid Class. Please restart game")
end

print("What would you like to do? CODE END")
input = io.read()
end

function love.draw()
    love.graphics.setColor( 0, 0, 0 )
    love.graphics.print( "Level: " .. pcStats.Level, 1, 1 )
    love.graphics.print( "Inv Space: " .. pcInv.InvSpace, 1, 20 )
    love.graphics.print( "Inv: " .. pcInv.Items, 1, 40 )
end

Here is player.lua This is where the game variables are stored

pcStats = {}
pcStats.Level = 1
pcStats.XP = nil
pcStats.Name = nil
pcStats.Class = nil
pcStats.Atk = nil   
pcStats.Def = nil

pcInv = {}
pcInv.InvSpace = nil
pcInv.Items.testsword = testing sword

And last but not least, here is the conf.lua used for love2d

function love.conf(t)
    t.modules.joystick = true  
    t.modules.audio = true      
    t.modules.keyboard = true   
    t.modules.event = true    
    t.modules.image = true      
    t.modules.graphics = true   
    t.modules.timer = true     
    t.modules.mouse = true      
    t.modules.sound = true     
    t.modules.thread = true
    t.modules.physics = true    
    t.console = true          
    t.title = "Lua RPG Alpha v0.0.1"        
    t.author = "Zach Herzer"
end

Upvotes: 1

Views: 3082

Answers (1)

Bartek Banachewicz
Bartek Banachewicz

Reputation: 39390

Line 15 is this:

    pcInv.Items.basicBow = Basic Bow

Basic Bow isn't valid Lua code. I am pretty sure you meant something else - perhaps a string?

pcInv.Items.basicBow = "Basic Bow"

While we're at it,

pcInv.Items.testsword = testing sword

has a similar problem.

Upvotes: 2

Related Questions