Need help for my loader...

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
XaafCode
Prole
Posts: 3
Joined: Wed Apr 26, 2017 12:41 pm

Need help for my loader...

Post by XaafCode »

Hello everyone,

I am making a custom level loader, but when I run it, it gives me an error saying "= expected near ..."

My code:

Code: Select all

Level = {}

function Level:get(map)
  if map ~= nil then
    level = map
  else
    level = "../levels/levelCrash"
  end
  
  return level
end

function Level:draw(level)
  Map = require level
  
  Map:create()
end

return Level
The exact error is: levelLoader.lua:16: '=' expected near 'Map'
Can someone help me fix this problem?

Thanks in advance,
- Xaaf Code
User avatar
OnACoffeeBreak
Prole
Posts: 28
Joined: Tue Apr 11, 2017 11:19 am

Re: Need help for my loader...

Post by OnACoffeeBreak »

If you have level.lua file, try putting quotes around level parameter in the require command:

Code: Select all

  Map = require "level"
http://lua-users.org/wiki/ModulesTutorial
XaafCode
Prole
Posts: 3
Joined: Wed Apr 26, 2017 12:41 pm

Re: Need help for my loader...

Post by XaafCode »

I know, but I want that it requires the value of the variable level...
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: Need help for my loader...

Post by Beelz »

Require is not a magic word, it is a function. With functions as long as you only have one argument and it's a string, then you do not need parenthesis. If you use a variable or concatenate a string, you'll need to enclose it.

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Need help for my loader...

Post by zorg »

So, to finish up the above info fragments, you want to do it like this:

Code: Select all

Map = require(level)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Need help for my loader...

Post by Sir_Silver »

I just wanted to say that that is some very strange code. You have your level object overriding what it is in the get method, which means that the level would lose the methods you've attached to it.

Also in your draw method, you are calling require and create map. That doesn't make any sense for something you would expect to be called in rendering.
XaafCode
Prole
Posts: 3
Joined: Wed Apr 26, 2017 12:41 pm

Re: Need help for my loader...

Post by XaafCode »

Thanks to all for replying, I have cleaned up and fixed my code now. Thanks! :D
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 44 guests