Page 1 of 2

[SOLVED] STI Not Working?

Posted: Tue Mar 01, 2022 4:26 pm
by DoggylovesLove2D
Hey All,

I'm currently struggling to get my tiled map to load properly. I followed a Youtube video ( https://youtu.be/dZzAxYrUMRg ) and it still doesn't work. I tried troubleshooting it myself and it still isn't working.

This is the error message I get:
Error

main.lua:28: attempt to call global 'sti' (a nil value)


Traceback

[love "callbacks.lua"]:228: in function 'handler'
main.lua:28: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'


I'm not sure what it is exactly trying to tell me and so I am lost and requesting some help.

I have attached the main.lua file I am using so hopefully that can help you guys with helping me.

Re: STI Not Working?

Posted: Wed Mar 02, 2022 2:46 pm
by nehu
Hi! :crazy:
i suposse that you only gave the main.lua (and no the rest of files) on purpuse.
i never used that library 'sti' or watched that video but i took a quick look at your code and saw two problems:
first, you have love.load() defined two times, like this:

Code: Select all

-- Load some default values 
function love.load() --1st time---
  --code
end
function love.load() --2nd time---
    map = sti("maps/map1.lua")
 end
 

and thats a problem bc when you define a function two times, it gets replaced, for example:

Code: Select all

function uwu()
	print(1)
end
function uwu()
	print(2)
end

uwu()

will print 2 bc the first time the function got defined, it got told to say 1, but we defined it again so it overwrites all the code of the function to print (2)

so you only should have all your load code in just one on love.load()

and the second thing i found is a bumb mistake that also annoyed me more than one time :death: :
LOCAL

in your code you did this to define sti:

Code: Select all

local sti = require "libraries/sti"
and local means that the variable you define will exist only on that block

so in this case the block starts with

Code: Select all

function love.load()
and ends when you end the function
and inside this block you define sti with local
meaning that sti will only exist on that block and attemping to call it outside that block will return nil
so when you try to call sti in the line 28, youre not calling a library, youre calling nil.
just delete the 'local' on line 7

fixing those two issues will(hopefully) stop löve to throw the error you mensioned! :P

here's a link to the lua manual about local variables and blocks if you need it: :monocle:
https://www.lua.org/pil/4.2.html

hope it helped! :nyu:

Re: STI Not Working?

Posted: Wed Mar 02, 2022 5:41 pm
by DoggylovesLove2D
Hello there,

Thanks for your help, but weirdly I am still facing some issues

here is the error code:

Error

libraries/sti/utils.lua:195: Could not open file ../GameLove2D/map.png. Does not exist.


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newImageData'
libraries/sti/utils.lua:195: in function 'fix_transparent_color'
libraries/sti/init.lua:106: in function 'init'
libraries/sti/init.lua:48: in function 'sti'
main.lua:8: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'

and also I'll provide all the files, I thought I did in the previous post but I guess not

Re: STI Not Working?

Posted: Wed Mar 02, 2022 6:33 pm
by ReFreezed
You cannot use ".." in file paths in LÖVE.

Re: STI Not Working?

Posted: Wed Mar 02, 2022 10:37 pm
by DoggylovesLove2D
Is there a way to change it?

Re: STI Not Working?

Posted: Thu Mar 03, 2022 6:12 am
by ReFreezed
I haven't used Tiled or STI, but you may have to get Tiled to export the data without ".." in the paths in the first place (unless you wanna make modifications to the STI library itself to resolve paths containing ".." automatically). Try having the Tiled files in the same folder as the images being used when you export the data.

Re: STI Not Working?

Posted: Thu Mar 03, 2022 7:26 pm
by Karai17
upload a full .zip or .love file of your game and we can take a look.

Re: STI Not Working?

Posted: Fri Mar 04, 2022 5:18 pm
by DoggylovesLove2D
Karai17 wrote: Thu Mar 03, 2022 7:26 pm upload a full .zip or .love file of your game and we can take a look.
Will do. I didn't realize I had to zip the file to be able to share it :?

Re: STI Not Working?

Posted: Fri Mar 04, 2022 8:36 pm
by nehu
ok
i made a quick search for STI
and looks like STI lets you use Tiled for the map creation

but looks like the map you exported with Tiled isn't written in LUA. you need to click on 'Export as' and select LUA format
this is shown on the minute 10 of the video :P

Re: STI Not Working?

Posted: Fri Mar 04, 2022 9:27 pm
by Karai17
yeah, your map.lua is just a renamed xml file.. it needs to be an actual lua file. File > Export As > Lua