How to call a function from one script to main.lua
Posted: Sun Sep 09, 2018 9:28 am
Hello everyone! Sorry if I am repeating a question, but I couldn't find anything.
I have a function named item1 in a file named items.lua, and I want to get the item1 function from that script and run it in main.lua.
Here is items.lua:
Here is main.lua (Not all of it, just the important part):
I am terribly sorry if there is answer for this somewhere, or if this is a really simplistic question; I am learning the ropes still
I have a function named item1 in a file named items.lua, and I want to get the item1 function from that script and run it in main.lua.
Here is items.lua:
Code: Select all
items = {}
centerX = love.graphics.getWidth() / 2
centerY = love.graphics.getHeight() / 2
function item1()
sprite = love.graphics.newImage('sprites/stick.png') -- Image used for item
health = 10 -- Health for item
love.graphics.draw(sprite, centerX, centerY) -- Draw the sprite, and put it in the center
end
return items
Code: Select all
-- Other require parts here
items = require("items")
-- Load everything
function love.load()
-- Load other scripts
items.item1()
-- Continue loading everything
end
-- Continue other functions