Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Tue Apr 12, 2016 3:21 am

Camacho wrote:so i tried to load an image with onEvent function and it doesn't work

Code: Select all

function onEvent
	if calledEvent == "Peta Jamaa Township 2" then
		img = Graphics.loadimage ("rumah.png")
		Graphics.placeSprite (1, img, 0, 0)
	end
end
help
function onEvent(calledEvent)

The error message will even tell you "( expected near if".

Alagirez
Ludwig von Koopa
Ludwig von Koopa
Posts: 3617
Joined: Tue Dec 02, 2014 2:28 am
Flair: Legalize Awooo!
Pronouns: He/Him/That wolf
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Alagirez » Tue Apr 12, 2016 3:23 am

Enjl wrote:
Camacho wrote:so i tried to load an image with onEvent function and it doesn't work

Code: Select all

function onEvent
	if calledEvent == "Peta Jamaa Township 2" then
		img = Graphics.loadimage ("rumah.png")
		Graphics.placeSprite (1, img, 0, 0)
	end
end
help
function onEvent(calledEvent)

The error message will even tell you "( expected near if".
Ok thx i will try to add "(calledEvent)" after "onEvent" function.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Tue Apr 12, 2016 7:28 pm

I'm using NPC:harm(HARM_TYPE_NPC) to simulate a bomb effect. I was able to isolate the address for the combo score multiplier that's used by this function; if you don't do anything to it, the score will keep increasing with each hit until it starts farming 1-ups. The address is 0xAC24 after the NPC array pointer:

local comboscoreaddress = mem(0x00B259E8,FIELD_DWORD)+0xAC24

It appears to work perfectly to alter the value mem(comboscoreaddress,FIELD_WORD) , then damage the NPCs, then set that value back to what it was originally.

My question is, can the NPC array pointer value at 0x00B259E8 change at any point while the game is running, or is it safe to assume the combo score address will stay the same after loading?


Edit: Also, how do you get a file path to go up one level? For example, to get Audio.playSFX to play the default sounds in the SMBX/sound folder.

Alagirez
Ludwig von Koopa
Ludwig von Koopa
Posts: 3617
Joined: Tue Dec 02, 2014 2:28 am
Flair: Legalize Awooo!
Pronouns: He/Him/That wolf
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Alagirez » Tue Apr 12, 2016 11:20 pm

ok so i tried this code
function onEvent(calledEvent)
if calledEvent == "Peta Jamaa Township 2" then
img = Graphics.loadimage ("rumah.png")
Graphics.placeSprite (1, img, 0, 0)
end
end
and a debug message appears "d:???/???/???/???/lunadll.lua:15: attempt to call field "loadimage" (a nil value)"

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Apr 13, 2016 12:37 am

Lua is case-sensitive. loadimage doesn't exist, loadImage does.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Wed Apr 13, 2016 5:37 am

Camacho wrote: Graphics.placeSprite (1, img, 0, 0)
You also shouldn't be using "placeSprite". Use "drawImage" instead.

I suggest you also read over some of the tutorials on the wiki and on the Lua home page. Here are some links to get you started:

http://www.lua.org/pil/1.html
http://wohlsoft.ru/pgewiki/How_To:_LunaLua_basics

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Thu Apr 14, 2016 12:31 pm

How can I spawn a coin on top of the player? I'm making the script and I want to give player another life if he dies.

I tried:

Code: Select all

mem(0x00B2C5AC,FIELD_WORD,mem(0x00B2C5AC,FIELD_WORD)+1)
But that doesn't work at all.

Either does

Code: Select all

mem(0x00B2C5A8,FIELD_WORD,100)
I mean it does kinda work, it gives a player 100 coins, but doesn't turn it into life. You need to collect another coin.

That's why I ask how to spawn a coin on a player.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Thu Apr 14, 2016 12:38 pm

0x00B2C5AC is a FIELD_FLOAT

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Thu Apr 14, 2016 12:44 pm

Enjl wrote:0x00B2C5AC is a FIELD_FLOAT
Oh. That explains everything.

Nerx
Swooper
Swooper
Posts: 75
Joined: Thu Apr 14, 2016 12:57 pm

Re: Need help with lua? - LunaLua General Help

Postby Nerx » Thu Apr 14, 2016 6:47 pm

How can I spawn in a block and then access it later? Just saving the returned Block object doesn't seem to work on the next frame.

EDIT: My specific code I was testing out, not sure if it's relevant tho

Code: Select all

local block

function onStart()
    block = Block.spawn(90, -200000, -200384)
    block.x = block.x + 1
end

function onTick()
    block.x = block.x + 1
end


Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Thu Apr 14, 2016 8:24 pm

Nerx wrote:How can I spawn in a block and then access it later?
You can't easily. You also can't just set block coordinates, as that can break their collision.

The best way to do this is to attach the new block to a layer, then use layer speeds to move it, as that will retain collision and give you a way to access the block.

Nerx
Swooper
Swooper
Posts: 75
Joined: Thu Apr 14, 2016 12:57 pm

Re: Need help with lua? - LunaLua General Help

Postby Nerx » Thu Apr 14, 2016 8:41 pm

Hoeloe wrote:
Nerx wrote:How can I spawn in a block and then access it later?
You can't easily. You also can't just set block coordinates, as that can break their collision.

The best way to do this is to attach the new block to a layer, then use layer speeds to move it, as that will retain collision and give you a way to access the block.
And if I need to change something about the block (slipperyness, contents) I can just loop over Block.get() and check for layerName? That makes sense, thank you :D

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Fri Apr 15, 2016 5:59 pm

Is there any way that I can make all paths and levels on my world map be drawn instantly when the player enters?

EDIT: Additionally, how can I hide levels (make them unplayable again) after the player has beaten them?

FanofSMBX
Ludwig von Koopa
Ludwig von Koopa
Posts: 3878
Joined: Sun Dec 22, 2013 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby FanofSMBX » Sat Apr 16, 2016 7:54 pm

Sorry if this is the wrong thread.

Everyone knows that some new things have been added like NPC health, immunity to hammers, and vspeed. But these require LunaLua coding or specific APIs. However, these could be combined with standard NPC txts. This would be insanely useful for custom graphics packs (moi) because they wouldn't overwrite any lua files and they could be self-contained. Could this please be added to the 2.0 agenda?

Also, it could also be done to add "rope=1" and "bouncyspike=1" to block.txts. But I don't really have any interest in making graphics of those and I know this could be harder.

h2643
Reznor
Reznor
Posts: 2890
Joined: Sat Dec 21, 2013 7:23 am
Contact:

Re: Need help with lua? - LunaLua General Help

Postby h2643 » Sun Apr 17, 2016 7:49 am

FanofSMBX wrote:Also, it could also be done to add "rope=1" and "bouncyspike=1" to block.txts. But I don't really have any interest in making graphics of those and I know this could be harder.
So basically apc.lua?
http://wohlsoft.ru/pgewiki/Apc.lua

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sun Apr 17, 2016 1:34 pm

Horikawa Otane wrote:
PixelPest wrote:Is there any way that I can make all paths and levels on my world map be drawn instantly when the player enters?

EDIT: Additionally, how can I hide levels (make them unplayable again) after the player has beaten them?
1) Not currently to the best of my knowledge

2) You can find their .lvl thing and change it to blank with LunaLua. Or disallow button presses while the player is over it. Lots of ways to disable this.

If you want to 'hide' it, you could display gfx over it that makes it appear hidden.
Thanks for the help. I'll draw an image overtop of it and make the player be unable to press a key to enter it

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Sun Apr 17, 2016 1:40 pm

Can I somehow change npc health? For example if I want goomba to die on 3 hits instead of one.

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sun Apr 17, 2016 2:57 pm

Mario_and_Luigi_55 wrote:Can I somehow change npc health? For example if I want goomba to die on 3 hits instead of one.
I would use function onNPCKill(): http://wohlsoft.ru/pgewiki/LunaLua_events and then just respawn the NPC in the same spot. Then you could implement a counter and when it reaches a certain point, make it so that the NPC does not respawn

FanofSMBX
Ludwig von Koopa
Ludwig von Koopa
Posts: 3878
Joined: Sun Dec 22, 2013 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby FanofSMBX » Sun Apr 17, 2016 3:05 pm

Mario_and_Luigi_55 wrote:Can I somehow change npc health? For example if I want goomba to die on 3 hits instead of one.
I found a api on the PGEwiki that does this.

zlaker
Reznor
Reznor
Posts: 2844
Joined: Fri Dec 20, 2013 1:46 pm

Re: Need help with lua? - LunaLua General Help

Postby zlaker » Sun Apr 17, 2016 3:09 pm

FanofSMBX wrote:
Mario_and_Luigi_55 wrote:Can I somehow change npc health? For example if I want goomba to die on 3 hits instead of one.
I found a api on the PGEwiki that does this.
then...why are you not telling him what the API is called?


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 7 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari