Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.
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?
User avatar
Mario_and_Luigi_55
Mega Mole
Mega Mole
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm
Current Project: Super Mario Bros Adventure

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Sun Apr 10, 2016 2:20 pm

Catastrophe wrote:
PixelPest wrote:
Catastrophe wrote:The code didn't crash when I added the other end but it's not making the blocks slippery. ???
Then use function onTick(). That should work
function onTick() also doesn't work.
Did you put next end?
Last edited by Mario_and_Luigi_55 on Sun Apr 10, 2016 2:24 pm, edited 2 times in total.
Image
Image

My best levels:
Goomba Lands - 5/10
Stars of the trees - 5.5/10
Koopa Cave - 3.42
Green Grass Hill - 3.42
Grassy Valley - 5.47

User avatar
Hani
Volcano Lotus
Volcano Lotus
Posts: 564
Joined: Mon Apr 13, 2015 6:34 pm
Flair: Spring 봄

Re: Need help with lua? - LunaLua General Help

Postby Hani » Sun Apr 10, 2016 2:21 pm

Mario_and_Luigi_55 wrote: Did you put next end?

Code: Select all

function onTick() 
end


for k,v in pairs(Block.get()) do 
   v.slippery = true
end
I think so..
Image

User avatar
Mario_and_Luigi_55
Mega Mole
Mega Mole
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm
Current Project: Super Mario Bros Adventure

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Sun Apr 10, 2016 2:24 pm

Catastrophe wrote:
Mario_and_Luigi_55 wrote: Did you put next end?

Code: Select all

function onTick() 
end


for k,v in pairs(Block.get()) do 
   v.slippery = true
end
I think so..

That way you qre ending function right after start.

Code: Select all

 function onTick()

for k,v in pairs(Block.get(id of block,-1)) do 
   v.slippery = true
end
end  
Image
Image

My best levels:
Goomba Lands - 5/10
Stars of the trees - 5.5/10
Koopa Cave - 3.42
Green Grass Hill - 3.42
Grassy Valley - 5.47

User avatar
Hani
Volcano Lotus
Volcano Lotus
Posts: 564
Joined: Mon Apr 13, 2015 6:34 pm
Flair: Spring 봄

Re: Need help with lua? - LunaLua General Help

Postby Hani » Sun Apr 10, 2016 2:27 pm

Mario_and_Luigi_55 wrote:
Catastrophe wrote:
Mario_and_Luigi_55 wrote: Did you put next end?

Code: Select all

function onTick() 
end


for k,v in pairs(Block.get()) do 
   v.slippery = true
end
I think so..

That way you qre ending function right after start.

Code: Select all

 function onTick()

for k,v in pairs(Block.get(id of block,-1)) do 
   v.slippery = true
end
end  
Thank you! I finally know a little bit more of lunalua coding now.
Image

User avatar
Quantix
Ripper II
Ripper II
Posts: 325
Joined: Tue Jan 26, 2016 5:04 pm

Re: Need help with lua? - LunaLua General Help

Postby Quantix » Sun Apr 10, 2016 3:19 pm

Okay, so I've used the raocoin2 lua, and when I copypaste the code from the wiki, which is this:

Code: Select all

raocoin = loadSharedAPI("raocoin2");
rc = raocoin.registerCurrency(274, true, 472, 66);
coins = raocoin.registerMemCurrency(0x00B2C5A8,FIELD_WORD,true,false,0,0,"coins.png");
Then I load a level,and I get this error:

Code: Select all

lunaworld.lua:2: attempt to index global 'raocoin' (a nil value)
I swear this error is really annoying. Is it because you're not supposed to put it in a lunaworld file or something?
viewtopic.php?f=69&p=286856#p286855

Generic Quote Collection:
Spoiler: show
Skant wrote:The egg will fuck you if you don't catch it
rockythechao wrote:f6 is an over-the-counter generic run-of-the-mill store-brand bootleg knockoff f5
some people wrote:The021stYoshiFromThe021stCentury: Who would win, a tophat wearing a tophat, or hoeloe wearing hoeloe?
Hoeloe: yes
glitch4: f6
rockythecomet: that's a trick question
rockythecomet: a top hat wearing a hoeloe
Waffles & Stuff (timocomlita) wrote:No matter what you do, it's impossible to get rid of the impossible.
Petrifying wrote:Piss off with your sex doll SMBX 2.0
Enjl wrote:it puts a twist on classic 4 step level design which i like to call "2 and a half steps backwards design"

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7619
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sun Apr 10, 2016 4:27 pm

Looks like you don't have the api. You can download it from http://wohlsoft.ru/pgewiki/Raocoin2.lua and put it into your LuaScriptsLib folder.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Mudkip
Lakitu
Lakitu
Posts: 465
Joined: Mon Jan 06, 2014 11:35 pm
Current Project: Something
Chat Username: ZA BARUDO

Re: Need help with lua? - LunaLua General Help

Postby Mudkip » Sun Apr 10, 2016 4:39 pm

How do I make Link-6 the only character with his own health bar for a whole episode?
And with her heart of silver, Silva!

User avatar
PixelPest
Link
Link
Posts: 7118
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sun Apr 10, 2016 7:51 pm

Mudkip wrote:How do I make Link-6 the only character with his own health bar for a whole episode?
Put this in your lunaworld.lua:

Code: Select all

if player.character == 5 then
    --health bar script
end 

User avatar
MECHDRAGON777
Pink Yoshi Egg
Pink Yoshi Egg
Posts: 6122
Joined: Fri Dec 20, 2013 6:40 pm
Flair: Nuclear Queen of Reversion.
Current Project: http://www.supermariobrosx.org/forums/v ... 9&start=10
Chat Username: 鬼人 正邪
Contact:

Re: Need help with lua? - LunaLua General Help

Postby MECHDRAGON777 » Mon Apr 11, 2016 12:30 am

PixelPest wrote:
Mudkip wrote:How do I make Link-6 the only character with his own health bar for a whole episode?
Put this in your lunaworld.lua:

Code: Select all

if player.character == 5 then
    --health bar script
end 
I thought you need to set the player to player 6. If the player gets hurt, it will go to player 2 or 1. Check if that is occurring, the set it to 6. That way, it will keep track, but if the health bar reaches 0, you need to use tbe "kill" command. It is later, so I can not think straight, bjt that should be the jeist of it.

ImageImageImage

Image

User avatar
Quill
Rydia
Rydia
Posts: 811
Joined: Tue Dec 03, 2013 12:51 pm
Current Project: Apocalypse of Foroze...?
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Quill » Mon Apr 11, 2016 2:33 am

lol

User avatar
PixelPest
Link
Link
Posts: 7118
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Mon Apr 11, 2016 7:02 am

MECHDRAGON777 wrote:
PixelPest wrote:
Mudkip wrote:How do I make Link-6 the only character with his own health bar for a whole episode?
Put this in your lunaworld.lua:

Code: Select all

if player.character == 5 then
    --health bar script
end 
I thought you need to set the player to player 6. If the player gets hurt, it will go to player 2 or 1. Check if that is occurring, the set it to 6. That way, it will keep track, but if the health bar reaches 0, you need to use tbe "kill" command. It is later, so I can not think straight, bjt that should be the jeist of it.
Sorry, didn't read the whole question. You just have to do this then:

Code: Select all

if Player.character == 5 and Player.powerup == 6 then
    --health bar script
end 
That should work. Btw MECHDRAGON777 you can't just set "player" to something, that's not how that works at all for what you're trying to do

User avatar
Hoeloe
Grinder
Grinder
Posts: 1055
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Mon Apr 11, 2016 7:38 am

PixelPest wrote: That should work.
No it won't. You've used "Player" when it should be "player". There is a big difference between the two.

User avatar
PixelPest
Link
Link
Posts: 7118
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Mon Apr 11, 2016 8:02 am

Hoeloe wrote:
PixelPest wrote: That should work.
No it won't. You've used "Player" when it should be "player". There is a big difference between the two.
Right. Sorry. So Mudkip, do:

Code: Select all

if player.character == 5 and player.powerup == 6 then
    --health bar script
end 
Last edited by PixelPest on Mon Apr 11, 2016 12:22 pm, edited 1 time in total.

User avatar
MECHDRAGON777
Pink Yoshi Egg
Pink Yoshi Egg
Posts: 6122
Joined: Fri Dec 20, 2013 6:40 pm
Flair: Nuclear Queen of Reversion.
Current Project: http://www.supermariobrosx.org/forums/v ... 9&start=10
Chat Username: 鬼人 正邪
Contact:

Re: Need help with lua? - LunaLua General Help

Postby MECHDRAGON777 » Mon Apr 11, 2016 8:25 am

PixelPest wrote:
Hoeloe wrote:
PixelPest wrote: That should work.
No it won't. You've used "Player" when it should be "player". There is a big difference between the two.
Right. Sorry. So RoundPiplup, do:

Code: Select all

if player.character == 5 and player.powerup == 6 then
    --health bar script
end 
Mudkip is the one asking though... I never wrote the code for him to use because I can not reference the wiki while on a phone. I also do not have the entire wiki printed out yet as of today... I was just trying to help a little bit.

ImageImageImage

Image

User avatar
Mudkip
Lakitu
Lakitu
Posts: 465
Joined: Mon Jan 06, 2014 11:35 pm
Current Project: Something
Chat Username: ZA BARUDO

Re: Need help with lua? - LunaLua General Help

Postby Mudkip » Mon Apr 11, 2016 1:00 pm

I copypaste'd the code you wrote but I still play as Link normally. Don't I need to activate the code first or something?
And with her heart of silver, Silva!

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7619
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Mon Apr 11, 2016 1:58 pm

PixelPest wrote: Right. Sorry. So Mudkip, do:

Code: Select all

if player.character == 5 and player.powerup == 6 then
    --health bar script
end 
What no
How is
how is what you're doing even remotely helpful.
He's asking how he should tackle a healthbar script and how to force the character to state 6 at all times.

While I won't write the code for you (mudkip), because it's important that you work this out for yourself, I'm gonna (unlike other people *nudge*) provide some sources and tips on what to do and how to tackle this.

-Setting the player to link and initially setting him to state 6 is no issue. Use function onStart() and player.powerup, as well as player.character, which you can find here:
http://wohlsoft.ru/pgewiki/Player_%28class%29
You might want to build in a check though for the latter.

-Setting the player powerup to 6 might be a bit tricky. If the player powerup was 1 before, link will start clipping through the ground. There are a few workarounds, but the safest is probably breifly setting the powerup state to 2 before setting it to 6.

-To impliment your own health bar you want to create a variable in the data class:
http://wohlsoft.ru/pgewiki/Data_%28class%29
The data class is a class which you can use to save variables between levels. Pyro made a tutorial on it, too: https://www.youtube.com/watch?v=dnTH_cBYZhs
By using it you can make a variable which will store the player's current HP. Once it reaches 0 you kill the player (once).

-The normal way how smbx handles health might sound to be obsolete, however you can still use it to detect changes to the player's hp.
http://wohlsoft.ru/pgewiki/SMBX_Player_Offsets
Offset 0x16 stores the number of hearts. Ideally you want this to be 2 at all times, breifly falling back to 1 when hit and going to 3 when getting a powerup for a frame or two. During that time you catch the difference and adjust your data class variable (and the player powerup if needed).

For a first-hand look on a health bar script like this, take a look at hudOfTime.lua. It does what I described here. Make sure to not copy the code though without having understood what it does, since else you might end up puzzled in a few weeks when something breaks somehow.
ImageImageImageImage
ImageImageImageImageImageImage

pal4
Fighter Fly
Fighter Fly
Posts: 63
Joined: Wed Dec 23, 2015 7:57 pm

Re: Need help with lua? - LunaLua General Help

Postby pal4 » Mon Apr 11, 2016 4:43 pm

Image
local hasGenerated = false;
local ran;

function onLoop()
tableOfBirdo = NPC.get(39, -1);
tableOfBirdoEggs = NPC.get(40, -1);
Text.print(tostring(ran),0,0)

if(tableOfBirdo[1] ~= nil) then
if(tonumber(tableOfBirdo[1]:mem(0xF0, FIELD_DFLOAT)) = 1) then
if(hasGenerated ~= true) then
ran = math.random(0, 2);
hasGenerated = true;
end
if(ran == 2) then
if(table.getn(tableOfBirdoEggs) > 0) then
tableOfBirdoEggs[table.getn(tableOfBirdoEggs)].id = 282;
playSFX(42);
end
end
end
if(tonumber(tableOfBirdo[1]:mem(0xF8, FIELD_DFLOAT)) == 280) then
hasGenerated = false;
end
end
end

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7619
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Mon Apr 11, 2016 4:45 pm

pal4 wrote:Image
local hasGenerated = false;
local ran;

function onLoop()
tableOfBirdo = NPC.get(39, -1);
tableOfBirdoEggs = NPC.get(40, -1);
Text.print(tostring(ran),0,0)

if(tableOfBirdo[1] ~= nil) then
if(tonumber(tableOfBirdo[1]:mem(0xF0, FIELD_DFLOAT)) = 1) then
if(hasGenerated ~= true) then
ran = math.random(0, 2);
hasGenerated = true;
end
if(ran == 2) then
if(table.getn(tableOfBirdoEggs) > 0) then
tableOfBirdoEggs[table.getn(tableOfBirdoEggs)].id = 282;
playSFX(42);
end
end
end
if(tonumber(tableOfBirdo[1]:mem(0xF8, FIELD_DFLOAT)) == 280) then
hasGenerated = false;
end
end
end
http://hastebin.com
Last edited by Enjl on Mon Apr 11, 2016 4:46 pm, edited 1 time in total.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
PixelPest
Link
Link
Posts: 7118
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Mon Apr 11, 2016 4:46 pm

pal4 wrote:Image

Code: Select all

local hasGenerated = false;
local ran;

function onLoop()
  tableOfBirdo = NPC.get(39, -1);
  tableOfBirdoEggs = NPC.get(40, -1);
  Text.print(tostring(ran),0,0)
 
  if(tableOfBirdo[1] ~= nil) then
    if(tonumber(tableOfBirdo[1]:mem(0xF0, FIELD_DFLOAT)) = 1) then
      if(hasGenerated ~= true) then
        ran = math.random(0, 2);
        hasGenerated = true;
      end
      if(ran == 2) then
        if(table.getn(tableOfBirdoEggs) > 0) then
          tableOfBirdoEggs[table.getn(tableOfBirdoEggs)].id = 282;
          playSFX(42);
        end
      end
    end
    if(tonumber(tableOfBirdo[1]:mem(0xF8, FIELD_DFLOAT)) == 280) then
      hasGenerated = false;
    end
  end
end
It might help if you mention your issue

User avatar
WerewolfGD
Wart
Wart
Posts: 3256
Joined: Tue Dec 02, 2014 2:28 am
Flair: Daily life of Alagirez
Current Project: Questioning my life
Chat Username: Alagirez
Contact:

Re: Need help with lua? - LunaLua General Help

Postby WerewolfGD » Tue Apr 12, 2016 2:17 am

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

A former SMBX level designner
If you want to to talk with me, go here : Alagirez#2056
Also a furry

Image
YT Channel |MxW2 for those who wants it
My osu! Profile | My twitter
Image

Awooo!


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 3 guests