[SOLVED] STI Not Working?

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.
DoggylovesLove2D
Prole
Posts: 6
Joined: Tue Mar 01, 2022 4:18 pm

[SOLVED] STI Not Working?

Post 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.
Attachments
main.lua
(2.45 KiB) Downloaded 154 times
Last edited by DoggylovesLove2D on Sat Mar 05, 2022 1:25 am, edited 1 time in total.
User avatar
nehu
Prole
Posts: 11
Joined: Fri Feb 25, 2022 1:12 am
Location: Argentina, Maybe under your bed

Re: STI Not Working?

Post 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:

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?

Post 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
Attachments
utils.lua
this is the one code the file the error is referencing
(4.76 KiB) Downloaded 140 times
map.lua
this is the map.lua code
(25.47 KiB) Downloaded 139 times
main.lua
this is the main code
(2.5 KiB) Downloaded 140 times
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: STI Not Working?

Post by ReFreezed »

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?

Post by DoggylovesLove2D »

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

Re: STI Not Working?

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

Re: STI Not Working?

Post by Karai17 »

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?

Post 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 :?
Attachments
MyGame2 - Copy.zip
(471.06 KiB) Downloaded 122 times
User avatar
nehu
Prole
Posts: 11
Joined: Fri Feb 25, 2022 1:12 am
Location: Argentina, Maybe under your bed

Re: STI Not Working?

Post 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

Code: Select all

for i, v in pairs(problems) do
	fix(v)
end
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: STI Not Working?

Post by Karai17 »

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é
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 37 guests