## [SOLVED] STI Not Working?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
DoggylovesLove2D
Prole
Posts: 6
Joined: Tue Mar 01, 2022 4:18 pm

### [SOLVED] STI Not Working?

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'
[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.
Attachments
main.lua
Last edited by DoggylovesLove2D on Sat Mar 05, 2022 1:25 am, edited 1 time in total.
nehu
Prole
Posts: 7
Joined: Fri Feb 25, 2022 1:12 am
Location: Argentina, Maybe under your bed

### Re: STI Not Working?

Hi!
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
--code
end
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)

and the second thing i found is a bumb mistake that also annoyed me more than one time :
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!

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

hope it helped!

Code: Select all

for i, v in pairs(problems) do
fix(v)
end

DoggylovesLove2D
Prole
Posts: 6
Joined: Tue Mar 01, 2022 4:18 pm

### Re: STI Not Working?

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'
[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
Attachments
utils.lua
this is the one code the file the error is referencing
map.lua
this is the map.lua code
main.lua
this is the main code
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

### Re: STI Not Working?

You cannot use ".." in file paths in LÖVE.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
DoggylovesLove2D
Prole
Posts: 6
Joined: Tue Mar 01, 2022 4:18 pm

### Re: STI Not Working?

Is there a way to change it?
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

### Re: STI Not Working?

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.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

### Re: STI Not Working?

upload a full .zip or .love file of your game and we can take a look.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
DoggylovesLove2D
Prole
Posts: 6
Joined: Tue Mar 01, 2022 4:18 pm

### Re: STI Not Working?

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
Attachments
MyGame2 - Copy.zip
nehu
Prole
Posts: 7
Joined: Fri Feb 25, 2022 1:12 am
Location: Argentina, Maybe under your bed

### Re: STI Not Working?

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

Code: Select all

for i, v in pairs(problems) do
fix(v)
end

Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

### Re: STI Not Working?

yeah, your map.lua is just a renamed xml file.. it needs to be an actual lua file. File > Export As > Lua
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

### Who is online

Users browsing this forum: Google [Bot] and 25 guests