I have two files: main.lua and map.lua. Essentially the main is just were I put my code and the map is a load, update, and draw function that handle the defining, collisions, and drawing of map items respectively. I have "require("map")" at the top of my main.lua outside of any functions (I have also tried to place it inside the load function).
When I try to run the program I get this error: "attempt to preform arithmetic on global 'woy' (a nil value)" (woy is a variable name)
How do I fix this?
Trying to split code into two files
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Trying to split code into two files
Can we see the code for both files? Obviously at some point in your code you're referring to "woy" but before it's defined. Where is it defined and where is it being called when it crashes? Make sure you're defining "woy" in "map" if that's where it's being defines and not in "main".
Re: Trying to split code into two files
https://pastebin.com/wY3Tv6s4 <- Code from main.luaJasoco wrote: ↑Sat Jul 29, 2017 7:45 pm Can we see the code for both files? Obviously at some point in your code you're referring to "woy" but before it's defined. Where is it defined and where is it being called when it crashes? Make sure you're defining "woy" in "map" if that's where it's being defines and not in "main".
https://pastebin.com/dg9bEw4x <- Code from map.lua
http://www.mediafire.com/file/e76xvxv2asx4fm1/love.rar <- Here's everything if you want to try to run it yourself (the two code files and two images) (if you want to just create your own filler images make player 16x16 and walls 16x160)
Re: Trying to split code into two files
You can't define love.update and love.load and so on more than once: the latest one will just replace the earlier ones. There are any number of ways to deal with that, but basically the map file should probably define some load and update and draw functions which are called from love.update etc. in your main file. And you might want to look into the various tools for creating lua modules and objects.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 97 guests