Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Moderator: Userbase Moderators
|
|
|
|
-
Murphmario
- 2025 Egg Hunter

- Posts: 2389
- Joined: Fri Dec 20, 2013 7:07 pm
- Pronouns: he/him
Postby Murphmario » Fri Mar 27, 2020 1:50 pm
Code: Select all function onTick()
for k,v in ipairs(NPC.get(210)) do
v.hp = v:mem(0x148, FIELD_FLOAT)
Text.print(v.hp, 100, 100)
if v.hp == 6 then
triggerEvent(Halfway)
end
end
end
Not sure what I'm missing here. Probably something dumb.
|
|
|
|
|
|
|
|
|
-
chasey1237
- Shy Guy

- Posts: 9
- Joined: Sat Nov 03, 2018 4:02 pm
Postby chasey1237 » Mon Mar 30, 2020 11:15 pm
is it possible to lock a character to have a powerup in a level so they start with it and not lose it? if so, tell me how!
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9890
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Tue Mar 31, 2020 3:55 am
Murphmario wrote: ↑Fri Mar 27, 2020 1:50 pm
Code: Select all function onTick()
for k,v in ipairs(NPC.get(210)) do
v.hp = v:mem(0x148, FIELD_FLOAT)
Text.print(v.hp, 100, 100)
if v.hp == 6 then
triggerEvent(Halfway)
end
end
end
Not sure what I'm missing here. Probably something dumb.
Not sure what you're trying to do. Rinkas don't have HP and triggering an event that isn't even a string every frame sounds like a silly thing to do.
chasey1237 wrote: ↑Mon Mar 30, 2020 11:15 pm
is it possible to lock a character to have a powerup in a level so they start with it and not lose it? if so, tell me how!
Just use the Beta 4 powerup filter blocks in the Misc. tab by sprinkling them throughout your level where players can get hit.
CrazyMew37 wrote: ↑Fri Mar 27, 2020 1:03 pm
Hello! I want to create a stage effect in one of the sections of my stage where the lighting of the level goes down and then goes up again in a repeating manner. Perhaps this could be for both the backgrounds, blocks, and NPCs (If Possible), to make it a bit of a challenge. The Speed of the Light fading away and fading back should be quick, but not too quick. How could I possibly do this? (Also, this is just for one entire section of the level. Not the whole thing or a part of a section.)
Are you looking for something like the editor darkness setting (with light sources) or a semitransparent black overlay over everything?
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 786
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Tue Mar 31, 2020 8:46 am
Could someone help me with this function?
Code: Select all local autoscroll = require("autoscroll")
function onEvent(p)
if p == "Gore Starts" then
autoscroll.scrollRight(4, (.7))
end
end
I'm trying to make the Screen Scroll once the Boss starts Moving.
Demo:
(Also what is the usual Speed of a Yellow Grinder?)
Thanks in Advance
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Tue Mar 31, 2020 9:44 am
To me, it looks like either your event name is wrong, the event isn't being triggered, or your Lua code isn't running at all.
Try hitting F2 when the game is running. That should show you which code files are currently running code, so if your luna.lua file isn't listed, it would mean that your code isn't running. If it is listed, it's likely to do with your events rather than your code. Remember, everything is case sensitive.
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 786
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Tue Mar 31, 2020 9:56 am
Hoeloe wrote: ↑Tue Mar 31, 2020 9:44 am
To me, it looks like either your event name is wrong, the event isn't being triggered, or your Lua code isn't running at all.
Try hitting F2 when the game is running. That should show you which code files are currently running code, so if your luna.lua file isn't listed, it would mean that your code isn't running. If it is listed, it's likely to do with your events rather than your code. Remember, everything is case sensitive.
My Lua Code is defenitly running since the Music Change (A Diffrent Code below) works. It also shows the Libary. Is there something I need
to do in the Event? The Event that should trigger the Scrolling currently only Hides the Idle Boss and Spawns the Active Boss.

|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Tue Mar 31, 2020 11:37 am
I would double check the name of the event. Also make sure your code doesn't have multiple "onEvent" functions. You can only have one function with a specific name, so if you have more than one, it won't work (though it would also give you a warning in this case).
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 786
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Tue Mar 31, 2020 11:48 am
Hoeloe wrote: ↑Tue Mar 31, 2020 11:37 am
I would double check the name of the event. Also make sure your code doesn't have multiple "onEvent" functions. You can only have one function with a specific name, so if you have more than one, it won't work (though it would also give you a warning in this case).
It has a second on Event Function, though it refers to two diffrent Events.

|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9890
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Tue Mar 31, 2020 12:04 pm
DrMekar wrote: ↑Tue Mar 31, 2020 11:48 am
Hoeloe wrote: ↑Tue Mar 31, 2020 11:37 am
I would double check the name of the event. Also make sure your code doesn't have multiple "onEvent" functions. You can only have one function with a specific name, so if you have more than one, it won't work (though it would also give you a warning in this case).
It has a second on Event Function, though it refers to two diffrent Events.
Merge the two. To re-iterate on what Hoeloe said: You cannot have two functions or variables with the same name. The one defined further down in the code will always REPLACE the previously defined one.
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 786
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Tue Mar 31, 2020 12:24 pm
Enjl wrote: ↑Tue Mar 31, 2020 12:04 pm
DrMekar wrote: ↑Tue Mar 31, 2020 11:48 am
Hoeloe wrote: ↑Tue Mar 31, 2020 11:37 am
I would double check the name of the event. Also make sure your code doesn't have multiple "onEvent" functions. You can only have one function with a specific name, so if you have more than one, it won't work (though it would also give you a warning in this case).
It has a second on Event Function, though it refers to two diffrent Events.
Merge the two. To re-iterate on what Hoeloe said: You cannot have two functions or variables with the same name. The one defined further down in the code will always REPLACE the previously defined one.
Oh, I got it to work with merging. Sorry for not writing yet. Thanks for the help 
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Tue Mar 31, 2020 4:36 pm
DrMekar wrote: ↑Tue Mar 31, 2020 12:24 pm
Oh, I got it to work with merging. Sorry for not writing yet. Thanks for the help
I should note: If you're asking for help like this, mentioning you had a warning showing up would have got to this point a lot faster. Don't leave our error messages or warnings, and don't just ignore them. Try reading them.
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 786
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Tue Mar 31, 2020 5:24 pm
Hoeloe wrote: ↑Tue Mar 31, 2020 4:36 pm
DrMekar wrote: ↑Tue Mar 31, 2020 12:24 pm
Oh, I got it to work with merging. Sorry for not writing yet. Thanks for the help
I should note: If you're asking for help like this, mentioning you had a warning showing up would have got to this point a lot faster. Don't leave our error messages or warnings, and don't just ignore them. Try reading them.
Noted for the Future  .
|
|
|
|
|
|
|
|
|
-
DigitalDetective47
- Bot

- Posts: 56
- Joined: Fri Mar 27, 2020 10:12 pm
- Pronouns: they/them
-
Contact:
Postby DigitalDetective47 » Wed Apr 15, 2020 10:19 pm
Code: Select all function onStart()
if player.character==CHARACTER_MARIO then
local playerName=Graphics.loadImage("name-1.png")
else
if player.character==CHARACTER_LUIGI then
local playerName=Graphics.loadImage("name-2.png")
else
local playerName=Graphics.loadImage("name-3.png")
end
end
Graphics.sprites.hardcoded["33-3"].img=playerName
end
name-1.png

name-2.png

name-3.png

NOTE: I don't need 2-player compatibility as my episode doesn't actively support that. Also, Peach & Link are banned characters in this episode.
Added in 5 minutes 45 seconds:
I should note that when I run this, it simply displays the 1UP text as normal, and does not display any error messages.
Added in 49 minutes 26 seconds:
I'm now using a different method to replace the 1UP graphic, and am getting this error:

Here is my new code: Code: Select all function onStart()
if player.character==CHARACTER_MARIO then
local playerName=Graphics.loadImage("name-1.png")
else
if player.character==CHARACTER_LUIGI then
local playerName=Graphics.loadImage("name-2.png")
else
local playerName=Graphics.loadImage("name-3.png")
end
end
Graphics.drawImageWP(playerName,0,0)
end
Obviously the (0,0) position for the image is only a placeholder, but I need to figure out why this is an error. By the way, the name files are the same as the ones from my previous post.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9890
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Thu Apr 16, 2020 12:47 am
Ninji2701 wrote: ↑Wed Apr 15, 2020 11:14 pm
Code: Select all function onStart()
if player.character==CHARACTER_MARIO then
local playerName=Graphics.loadImage("name-1.png")
else
if player.character==CHARACTER_LUIGI then
local playerName=Graphics.loadImage("name-2.png")
else
local playerName=Graphics.loadImage("name-3.png")
end
end
Graphics.sprites.hardcoded["33-3"].img=playerName
end
Im on mobile so no links but:
1. Google what the local keyword does in lua
2. Go back to replacing thehardcoded image or stop loading your image anew in every frame
|
|
|
|
|
|
|
|
|
-
DigitalDetective47
- Bot

- Posts: 56
- Joined: Fri Mar 27, 2020 10:12 pm
- Pronouns: they/them
-
Contact:
Postby DigitalDetective47 » Thu Apr 16, 2020 7:20 am
Enjl wrote: ↑Thu Apr 16, 2020 12:47 am 1. Google what the local keyword does in lua
Fixed that, but still get the same error. Enjl wrote: ↑Thu Apr 16, 2020 12:47 am 2. Go back to replacing thehardcoded image or stop loading your image anew in every frame
This can't be the case for a few reasons. - I want the image to change based on what player you are playing as.I now realize that you meant replacing the hardcoded image in the lua script.
- When replacing the hardcoded image, the player name overlaps with the lives counter.
- This function is called from onStart().
- The error message appears before the first frame is shown.
Added in 22 minutes 45 seconds:
I JUST FIGURED OUT THE PROBLEM! The issue actually was that I wasn't defining layer priority for the image.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9890
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Thu Apr 16, 2020 7:44 am
Can you show your script now that the scoping issue is fixed?
|
|
|
|
|
|
|
|
|
-
DigitalDetective47
- Bot

- Posts: 56
- Joined: Fri Mar 27, 2020 10:12 pm
- Pronouns: they/them
-
Contact:
Postby DigitalDetective47 » Thu Apr 16, 2020 12:45 pm
Code: Select all function onStart()
if player.character==CHARACTER_MARIO then
playerName=Graphics.loadImageResolved("name-1.png")
else
if player.character==CHARACTER_LUIGI then
playerName=Graphics.loadImageResolved("name-2.png")
else
playerName=Graphics.loadImageResolved("name-3.png")
end
end
end
function onDraw()
Graphics.drawImageWP(playerName,0,0,6)
end
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9890
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Thu Apr 16, 2020 12:52 pm
Ah, just noticed you figured it out in the previous post. That's good. Some more suggestions for this code:
1) I recommend defining the playerName variable outside of functions at the top of the code to restrict it to the code's scope. Currently, it has no scope limitation, so other scripts could potentially access it. You can just do this at the top of the code:
2) Worth noting is that this doesn't account for player character changes. Here's a little modification that accounts for character switches mid-level:
Code: Select all local playerName = {
[CHARACTER_MARIO] = Graphics.loadImageResolved("name-1.png"),
[CHARACTER_LUIGI] = Graphics.loadImageResolved("name-2.png"),
[CHARACTER_TOAD] = Graphics.loadImageResolved("name-3.png"),
}
function onDraw()
if (playerName[player.character] ~= nil then
Graphics.drawImageWP(playerName[player.character],0,0,6)
end
end
This causes the onDraw code to draw the image corresponding to the player's current character, by using a lookup table (looks up the image based on the player character index as the key).
|
|
|
|
|
|
|
|
|
-
DigitalDetective47
- Bot

- Posts: 56
- Joined: Fri Mar 27, 2020 10:12 pm
- Pronouns: they/them
-
Contact:
Postby DigitalDetective47 » Thu Apr 16, 2020 6:46 pm
Code: Select all local worldPlayerDisable={}
--config
local allowedPlayers={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}--List of characters allowed in the episode. Should usually match the flags set in the 'Disable characters' field of the your world map.
--/config
local playerMask={}
for i=1,#allowedPlayers do
playerMask[allowedPlayers[i]]=true
end
function testPlayer()
for playerID,playerInfo in ipairs(Player.get())do
if((not playerMask[playerInfo.character])or player.character==player2.character)then
if playerInfo.rightKeyPressed then
while((not playerMask[playerInfo.character])or player.character==player2.character)do
playerInfo.character=playerInfo.character%allowedPlayers[#allowedPlayers]+1
end
else
while((not playerMask[playerInfo.character])or player.character==player2.character)do
playerInfo.character=(playerInfo.character-2)%allowedPlayers[#allowedPlayers]+1
end
end
end
end
end
function worldPlayerDisable.onInitAPI()
registerEvent(worldPlayerDisable,"onInputUpdate","testPlayer")
end
return worldPlayerDisable
For some reason the testPlayer() function is never run.
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Thu Apr 16, 2020 9:02 pm
When registering events, you supply a library table ("worldPlayerDisable", here), and a function name ("testPlayer"). The code will then try to run "library.function", i.e. "worldPlayerDisable.testPlayer", in your case. Your function needs to be a member function of your library table.
|
|
|
|
|
Return to “LunaLua Help”
Users browsing this forum: No registered users and 1 guest
|