Page 62 of 76
Re: Need help with lua? - LunaLua General Help
Posted: Fri Jan 19, 2018 9:02 pm
by PixelPest
Enjl wrote:Notxarb wrote:Do global variables save to the save file automatically? If not, how can we save variables to the save file?
https://wohlsoft.ru/pgewiki/Data_(class)
We're streamlining the system and making it easier to use with the next release, but for now, gotta use this.
It's essentially a table which you write and read from with :set and :get, using :save to save stuff to the file.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Jan 19, 2018 9:03 pm
by Emral
Just copypaste it into your url bar?
Re: Need help with lua? - LunaLua General Help
Posted: Fri Jan 19, 2018 9:17 pm
by Novarender
Enjl wrote:Just copypaste it into your url bar?
I suppose... but clicking on it is easier
I noticed some unnecessary folders in the data folder. What is the purpose of:
_ini_examples
gif-recordings
Oh wait, I guess that's it. Can I safely delete these?
Also, how does the LuaScriptsLib folder work?
I know it has implemented scripts that you can call on at any time, but how does this work?
What are the folders in that folder for-- just demonstrations?
Also, how does relaying variables from a LuaScript to an original script work?
I'm kind of confused here...
Re: Need help with lua? - LunaLua General Help
Posted: Fri Jan 19, 2018 9:21 pm
by Emral
ini_examples includes examples of ini files like music.ini and sounds.ini which you can copy over and modify to replace base sounds and music
gif recordings is like screenshots but animated. Press F11 in game to start/stop a recording.
Use API.load("apiname") to load a library. API.load also searches in luascriptslib. You can search in its subfolders by changing your function call to:
API.load("folder/apiname"). Don't add ".lua" to the filename.
Some scripts expose some of their variables. When loading the scripts, you can store them in variables:
local colliders = API.load("colliders")
and then call their exposed variables and functions:
colliders.Box(0,0,32,32)
Re: Need help with lua? - LunaLua General Help
Posted: Sat Jan 20, 2018 11:13 am
by Kley
Notxarb wrote:PixelPest wrote:Notxarb wrote:If I want to make a "Time's Up!" graphic and display it when the time runs out, where should I put that graphic and how can I access it in an lua script?
Also, is there no way to make music play faster?
My mistake it was 0x13E. Sorry.
To load a graphics use the Graphics.loadImage function with the argument being the file path. You can place the file in your custom graphics folder along with your lunadll.lua file and your file path will just be the name of your file. Then draw it with Graphics.drawImageWP at a priority of 5 (HUD priority). You also could possibly just use Text.printWP or textblox.lua as well depending on how complicated you want the text to be instead of loading an image file. There's no way to modify music files rn but you can just use a program outside of SMBX to change the speed of the music file and then load and play it in LunaLua
Ok thanks. Also, I suspected I'd have to do that to the music, but that means I'll have to have nearly twice as many songs, and believe me I will be having LOTS of songs in my episode.
If you think about it, do you think you could make artificial 4-players by cloning player 1 and 2 and having player 3 and 4 control those clones?
Also, will 4-players be added in Beta 4? When will Beta 4 come out?
Notxarb wrote:We all know how you can travel across any adjacent paths on the world map. Could you use lua scripts to program individual paths so that Mario can only travel across connected parts of paths?
please stop the double posting
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 21, 2018 9:16 am
by The Dwarven Digger
Anyone know how I would make a monty mole? I'm going to be using them as the main enemy in one of my levels, and they'll show up in a few other levels too. I don't care which NPC they replace, and I've got a spritesheet with the SMW moles that I'm going to have to make into an NPC graphic anyway. I'm looking for both types, the one that comes out of the wall and the one that comes from the floor.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 21, 2018 9:28 am
by Taycamgame
They are probably coming in beta 4, so i'd wait for that.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 21, 2018 2:21 pm
by Emral
mfw they're still WIP i should yell at pyro to finish them
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 21, 2018 6:34 pm
by Novarender
It doesn't work when I try to set the player's speedY value.
Code: Select all
function onKeyDown(keycode)
if keycode == KEY_JUMP then
if player.downKeyPressing then
Text.print("YES",64,64)
player.speedY = -30
end
end
end
EDIT: Wait, is the normal jump overriding this? When I do it in the air it works...
How can I override the normal jump?
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 21, 2018 6:36 pm
by PixelPest
Notxarb wrote:It doesn't work when I try to set the player's speedY value.
Code: Select all
function onKeyDown(keycode)
if keycode == KEY_JUMP then
if player.downKeyPressing then
Text.print("YES",64,64)
player.speedY = -30
end
end
end
What file do you have this in? Also btw -30 is going to shoot the player upwards
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 21, 2018 6:38 pm
by Novarender
PixelPest wrote:Notxarb wrote:It doesn't work when I try to set the player's speedY value.
Code: Select all
function onKeyDown(keycode)
if keycode == KEY_JUMP then
if player.downKeyPressing then
Text.print("YES",64,64)
player.speedY = -30
end
end
end
What file do you have this in? Also btw -30 is going to shoot the player upwards
It's .lua.
Also, I want it to shoot me upwards. This is the start of a backflip.
As I edited in my comment above, I think the normal jump is overriding it.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 21, 2018 6:40 pm
by PixelPest
Notxarb wrote:PixelPest wrote:Notxarb wrote:It doesn't work when I try to set the player's speedY value.
Code: Select all
function onKeyDown(keycode)
if keycode == KEY_JUMP then
if player.downKeyPressing then
Text.print("YES",64,64)
player.speedY = -30
end
end
end
What file do you have this in? Also btw -30 is going to shoot the player upwards
It's .lua.
Also, I want it to shoot me upwards. This is the start of a backflip.
As I edited in my comment above, I think the normal jump is overriding it.
What is your file called though? And are you seeing the text printed? Also try doing it in onInputUpdate and test for player.downKeyPressing
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 21, 2018 6:44 pm
by Novarender
Ok, onInputUpdate worked.
My file is called lunadll (.lua) and yes I can see the printed text.
But now I have another problem:
Code: Select all
function onInputUpdate()
if player.jumpKeyPressing then
if player.downKeyPressing then
if player:mem(0x146, FIELD_WORD) == 1 then
Text.print("YES",64,64)
player.speedY = -30
end
end
end
end
This sets his Y speed when both feet are touching the ground, but he leaves the ground too fast and it is not set.
Is there any way I can work around this?
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 28, 2018 1:58 pm
by An Absolute Loser
I seem to have encountered something extremely odd while attempting to use the Raocoin2.lua API on SMBX2 Beta 3. I haven't done anything besides attempting to collect a singular coin and it gives me the following error message.
https://imgur.com/a/jVdOp
the only thing I have inside of lunaworld.lua (as the PGE page said to put inside).
Code: Select all
local raocoin = API.load("raocoin2");
local coins = raocoin.registerMemCurrency(0x00B2C5A8,FIELD_WORD,true,false);
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jan 28, 2018 2:49 pm
by PixelPest
An Absolute Loser wrote:I seem to have encountered something extremely odd while attempting to use the Raocoin2.lua API on SMBX2 Beta 3. I haven't done anything besides attempting to collect a singular coin and it gives me the following error message.
https://imgur.com/a/jVdOp
the only thing I have inside of lunaworld.lua (as the PGE page said to put inside).
Code: Select all
local raocoin = API.load("raocoin2");
local coins = raocoin.registerMemCurrency(0x00B2C5A8,FIELD_WORD,true,false);
I've never actually worked with raocoin2.lua before and didn't get a lot of time to figure out the inner workings of it, so I'm not completely confident in this fix. Basically the issue is that it never creates an entry within the currencyCache table and then tries to reference it on 357. I instead made it reference the memcurrencyCache table and tweaked and added a few lines to set up the table itself. I did a little bit of testing and this fix seems to work pretty well, at least with the set, get, and save methods in addition to initializing it (which is all I tested).
The modified code is here:
https://hastebin.com/uzeduvivit.lua.
Copy it into a new .lua file and name the file "local_raocoin2.lua" and put it in the same directory as your lunaworld.lua file. Then instead of calling API.load("raocoin2"); just call API.load("local_raocoin2"); in your lunaworld.lua file
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jan 29, 2018 1:35 am
by Chaotic Gaming
Spinda wrote:couldnt you just set the lives (memory 0x00B2C5AC) to 99 at the start of the level?
If you set it like so:
On OnStart() which runs at the beginning of each level and beginning of the overworld, it does not work! So no.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jan 29, 2018 3:34 am
by The0x539
CC_Comedic_Comentator wrote:On OnStart() which runs at the beginning of each level and beginning of the overworld, it does not work! So no.
OnStart does not. onStart does. These things are important.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jan 29, 2018 10:36 am
by The Dwarven Digger
The0x539 wrote:CC_Comedic_Comentator wrote:On OnStart() which runs at the beginning of each level and beginning of the overworld, it does not work! So no.
OnStart does not. onStart does. These things are important.
Ah yes, the classic programmer's error of incorrect capitalisation/format. Can be very hard to debug if you don't spot it.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jan 29, 2018 5:56 pm
by Chaotic Gaming
The0x539 wrote:CC_Comedic_Comentator wrote:On OnStart() which runs at the beginning of each level and beginning of the overworld, it does not work! So no.
OnStart does not. onStart does. These things are important.
Correction: I forgot to edit my post last night. turns out I was saving the changes as a .lua.txt file by accident. Apparently Notepad on Windows 7 got confused which file format I had. XD
In sum, Adding mem(0x00B2C5AC, FIELD_FLOAT, 99) as suggested works to a degree. The world map shows the lost life, it is restored to 99 when you enter a level again. Can Lua edit the overworld yet? Maybe that could fix it if the code could be injected during the overworld?
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jan 29, 2018 6:05 pm
by The0x539
CC_Comedic_Comentator wrote:The0x539 wrote:CC_Comedic_Comentator wrote:On OnStart() which runs at the beginning of each level and beginning of the overworld, it does not work! So no.
OnStart does not. onStart does. These things are important.
Correction: I forgot to edit my post last night. turns out I was saving the changes as a .lua.txt file by accident. Apparently Notepad on Windows 7 got confused which file format I had. XD
In sum, Adding mem(0x00B2C5AC, FIELD_FLOAT, 99) as suggested works to a degree. The world map shows the lost life, it is restored to 99 when you enter a level again. Can Lua edit the overworld yet? Maybe that could fix it if the code could be injected during the overworld?
lunaoverworld.lua (map.lua in beta 4) will run on the overworld, generally using the same event names.