Page 12 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:20 pm
by Mario_and_Luigi_55
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?

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:21 pm
by Hani
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..

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:24 pm
by Mario_and_Luigi_55
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  

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:27 pm
by Hani
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 3:19 pm
by Quantix
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?

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 4:27 pm
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 4:39 pm
by Mudkip
How do I make Link-6 the only character with his own health bar for a whole episode?

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 7:51 pm
by PixelPest
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 

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 12:30 am
by MECHDRAGON777
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.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 2:33 am
by Quill
lol

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 7:02 am
by PixelPest
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

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 7:38 am
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 8:02 am
by PixelPest
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 

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 8:25 am
by MECHDRAGON777
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.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 1:00 pm
by Mudkip
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?

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 1:58 pm
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 4:43 pm
by pal4
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

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 4:45 pm
by Emral
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

Re: Need help with lua? - LunaLua General Help

Posted: Mon Apr 11, 2016 4:46 pm
by PixelPest
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

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 12, 2016 2:17 am
by Alagirez
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