Tic-80: dofile() in 0.80.1173-dev

Created on 14 May 2020  路  16Comments  路  Source: nesbox/TIC-80

dofile(somefile.lua) gives an 'unknown method' error when running a cart.

Most helpful comment

ok, I got it, we'll add #include directive or something for the text carts in next version :)

All 16 comments

dofile() was removed in .80 with the issue #715, but you can save carts in text format now
use

save game.lua
folder

and open game.lua in any text editor you want, TIC will automatically load the changes.

Ah ok thanks.

Issuing 'save game.lua' creates a file which includes sfx, tiles etc. TIC loads the changes after editing but I can't run the cart since eof is expected after TIC()...end

What am I doing wrong?

don't know, pls show your text cart

Issue 'new' at prompt, replace default 'hello world' code and save as 'test.lua'. Opening test lua in a text editor, it contains this:

[EDIT: the sections are headed TILES etc but don't show in code here on github]
`

function TIC()
cls(0)
print('Hello',0,0,12)

end

--
-- 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc
-- 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c
-- 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc
-- 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c
-- 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
-- 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
-- 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
-- 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
--

--
-- 000:00000000ffffffff00000000ffffffff
-- 001:0123456789abcdeffedcba9876543210
-- 002:0123456789abcdef0123456789abcdef
-- 003:ffffffffffffffff00123456789abcde
--

--
-- 000:030003000300030003000300030003000300030003000300030003000300030003000300030003000300030003000300030003000300030003000300305000000000
--

--
-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
--

`

Oh, I see, I have to load test.lua again before trying to run it. Seems like an unnecessary extra step compared to just using dofile() and ctrl+r.

It's weird because I don't see <TILES> tags and etc, did you remove them manually?
This is how the default cart looks in the text format:

-- title:  game title
-- author: game developer
-- desc:   short description
-- script: lua

t=0
x=96
y=24

function TIC()

    if btn(0) then y=y-1 end
    if btn(1) then y=y+1 end
    if btn(2) then x=x-1 end
    if btn(3) then x=x+1 end

    cls(13)
    spr(1+t%60//30*2,x,y,14,3,0,0,2,2)
    print("HELLO WORLD!",84,84)
    t=t+1
end

-- <TILES>
-- 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc
-- 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c
-- 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc
-- 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c
-- 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
-- 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
-- 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
-- 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
-- </TILES>

-- <WAVES>
-- 000:00000000ffffffff00000000ffffffff
-- 001:0123456789abcdeffedcba9876543210
-- 002:0123456789abcdef0123456789abcdef
-- </WAVES>

-- <SFX>
-- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
-- </SFX>

-- <PALETTE>
-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
-- </PALETTE>

No I just pasted the text into github 'code' block - they are there in the original file just not showing here on github

Having the sprite, audio data etc stored in the lua file also means it will be easy to accidentally change it and any such change won't show up like an error in code would.

Have to agree that it's less error-prone if only the code is open in external editor (i.e., with dofile), because you might draw a sprite in TIC, forget to save, edit code in external editor, save -> sprite gone!

I've somewhat accustomed to this new .lua-cart based workflow, but these mishaps still happen time to time.

I've suggested that a separate resource file is created alongside the .lua file rather than have the data tacked on at the end - example.res could then be created/loaded automatically when example.lua is saved/loaded.

Have to agree that it's less error-prone if only the code is open in external editor (i.e., with dofile), because you might draw a sprite in TIC, forget to save, edit code in external editor, save -> sprite gone!

I've somewhat accustomed to this new .lua-cart based workflow, but these mishaps still happen time to time.

You will see a warning message in this case and the cart won't be loaded.

Have to agree that it's less error-prone if only the code is open in external editor (i.e., with dofile), because you might draw a sprite in TIC, forget to save, edit code in external editor, save -> sprite gone!
I've somewhat accustomed to this new .lua-cart based workflow, but these mishaps still happen time to time.

You will see a warning message in this case and the cart won't be loaded.
The problem there is that you might still have unsaved work you want to keep in both TIC's sprite editor and in an external code editor. How would you resolve that? A separate .res file would only contain changes saved in TIC's sprite (etc) editors. I think that's a better idea than having the resources together with the code in a lua file (but still not as good as using dofile() :D )

Have to agree that it's less error-prone if only the code is open in external editor (i.e., with dofile), because you might draw a sprite in TIC, forget to save, edit code in external editor, save -> sprite gone!
I've somewhat accustomed to this new .lua-cart based workflow, but these mishaps still happen time to time.

You will see a warning message in this case and the cart won't be loaded.

Yeah, it's certainly helpful!

Nevertheless, my dumb ass has clicked on the "yes i DO want to load and wipe my progress" button a few too many times... 馃槄

ok, I got it, we'll add #include directive or something for the text carts in next version :)

@borbware If it's helpful, I made a scriptpacker Node.js script that will pack all your scripts into one, while keeping dependencies in place.

See the scriptpacker Lua tests for an example of what it ends up looking like. It starts with an input file, bundles all the dependencies, and then outputs them to one file.

Used it to make Dangerous Dave for TIC-80. You keep one .tic file, run scriptpacker and then run tic80 cart.tic -code output.lua -sprites sprites.gif.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sssilver picture sssilver  路  3Comments

BuoYancYdabl picture BuoYancYdabl  路  5Comments

fangzhangmnm picture fangzhangmnm  路  3Comments

Terumoc picture Terumoc  路  6Comments

codeartisticninja picture codeartisticninja  路  4Comments