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?
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Wed Nov 07, 2018 7:50 pm
That's really not the best way to use imagic. The idea is to create objects using functions like imagic.Circle once, then draw them. You apply the textures at the creation stage, not at the draw stage.
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Wed Nov 07, 2018 8:07 pm
How exactly can I do that? I don't really know how this code works, it's just a mod of nsmbwalls.lua.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9886
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Thu Nov 08, 2018 1:20 am
Notxarb wrote: ↑Wed Nov 07, 2018 6:19 pm
Enjl wrote: ↑Wed Nov 07, 2018 5:47 pm
Notxarb wrote: ↑Wed Nov 07, 2018 5:13 pm
How to have a plain black texture?
Code: Select all local left,top,right,bottom
local shouldRenderToScene
local renderPrio
Graphics.glDraw{
vertexCoords={left,top,right,top,right,bottom,left,bottom},
primitive=Graphics.GL_TRIANGLE_FAN,
sceneCoords=shouldRenderToScene,
color={0,0,0,1},
priority=renderPrio
}
Replace the variables and you're set. No texture needed.
I have absolutely no idea how imagic or drawing graphics works, but I tried to replace the texture with the color property and I got white instead.
I don't know how imagic works either so I just posted a working glDraw call that just needs a couple of coordinates and to know whether it should render to scene.
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Thu Nov 08, 2018 8:37 am
Notxarb wrote: ↑Wed Nov 07, 2018 8:07 pm
How exactly can I do that? I don't really know how this code works, it's just a mod of nsmbwalls.lua.
The problem that's stopping the code you tried to use from working is that colours and textures are not interchangeable. By swapping out the draw colour (which is used to tint the object) with a texture, you made it so the code can no longer understand what you were trying to do, so it just substituted the default white.
To use a texture on an imagic object, you need to fill it in at the create step, which is in the imagic.Circle function. You do this by adding in a texture argument, and assigning your texture there.
The less obvious issue is that you're creating new imagic objects every time you draw them. This is very heavy on performance, and not how imagic was designed to be used. The way it's meant to be used is by assigning the result of a creation function (such as imagic.Circle) to a variable, and then drawing that. This is what you're doing here, however you are also re-creating the object every frame, which is not necessary. Ideally you'd simply move the imagic.Circle function out of onDraw and only run it as few times as possible.
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Thu Nov 08, 2018 5:12 pm
Hoeloe wrote: ↑Thu Nov 08, 2018 8:37 am
Notxarb wrote: ↑Wed Nov 07, 2018 8:07 pm
How exactly can I do that? I don't really know how this code works, it's just a mod of nsmbwalls.lua.
The problem that's stopping the code you tried to use from working is that colours and textures are not interchangeable. By swapping out the draw colour (which is used to tint the object) with a texture, you made it so the code can no longer understand what you were trying to do, so it just substituted the default white.
To use a texture on an imagic object, you need to fill it in at the create step, which is in the imagic.Circle function. You do this by adding in a texture argument, and assigning your texture there.
The less obvious issue is that you're creating new imagic objects every time you draw them. This is very heavy on performance, and not how imagic was designed to be used. The way it's meant to be used is by assigning the result of a creation function (such as imagic.Circle) to a variable, and then drawing that. This is what you're doing here, however you are also re-creating the object every frame, which is not necessary. Ideally you'd simply move the imagic.Circle function out of onDraw and only run it as few times as possible.
It looks like it is doing it correctly. Assuming that overlays[k] is a variable containing the circle, it is what's drawn and not the circle itself. Even so, exactly how can I make it a pure black color? Do I need to assign a black texture or a blank texture with a black color?
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Fri Nov 09, 2018 2:24 pm
Notxarb wrote: ↑Thu Nov 08, 2018 5:12 pm
It looks like it is doing it correctly. Assuming that overlays[k] is a variable containing the circle, it is what's drawn and not the circle itself. Even so, exactly how can I make it a pure black color? Do I need to assign a black texture or a blank texture with a black color?
The reason it's not quite doing it correctly is that it's re-assigning overlays[k] every frame, when it only actually needs to do so once. This means it spends a lot of time creating and destroying objects, rather than just creating one once and drawing it repeatedly.
As for your other question, colour tints are applied multiplicatively. This means that your tint colour is multiplied with the source colour to produce the final colour. This means that a white tint will not tint the image at all (since white is represented by 1 in the RGB channels), and a black tint will produce solid black (since black is represented by 0 in the RGB channels).
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Sat Nov 10, 2018 9:33 am
Hoeloe wrote: ↑Fri Nov 09, 2018 2:24 pm
Notxarb wrote: ↑Thu Nov 08, 2018 5:12 pm
It looks like it is doing it correctly. Assuming that overlays[k] is a variable containing the circle, it is what's drawn and not the circle itself. Even so, exactly how can I make it a pure black color? Do I need to assign a black texture or a blank texture with a black color?
The reason it's not quite doing it correctly is that it's re-assigning overlays[k] every frame, when it only actually needs to do so once. This means it spends a lot of time creating and destroying objects, rather than just creating one once and drawing it repeatedly.
As for your other question, colour tints are applied multiplicatively. This means that your tint colour is multiplied with the source colour to produce the final colour. This means that a white tint will not tint the image at all (since white is represented by 1 in the RGB channels), and a black tint will produce solid black (since black is represented by 0 in the RGB channels).
I think what's going on here is that it updates the texture every frame (and the texture always changes), and it draws it right after. What I want to do is instead to assign it to a solid black color once and draw that every frame instead. So how exactly can I give it a solid black color (that texture isn't needed)?
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Sun Nov 11, 2018 11:00 pm
That is not what's happening. Please read what I posted. You just need to tint it black, with no texture, as I already said.
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Tue Nov 13, 2018 5:31 pm
I have no idea what I'm doing wrong, but it's still not working. Removing the texture results in a white circle and keeping it results in nothing at all. It completely ignores the color property.
Code: Select all overlays[k] = imagic.Circle
{
radius = r,
x = playerCenterX,
y = playerCenterY,
scene = true,
-- texture = overlayBuffer,
color={0,0,0,1},
-- filltype = imagic.TEX_FILL,
texoffsetX = (centerOnScreenX - 400)/800,
texoffsetY = (centerOnScreenY - 300)/600
}
--overlays[k]:ScaleTexture((800) / (2 * r), (600) / (2 * r))
--draw the overlay effect
overlays[k]:Draw(VE_PRIORITY[k] + .1, 0xffffffff)
I tried to make it only create the object once then keep drawing it, but I realized that drawing it destroyed the object. As it needed to be drawn every frame, it also needed to be recreated every frame.
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Tue Nov 13, 2018 7:14 pm
That would be because your colour is still white (0xffffffff). The imagic object itself does not support a colour argument, so trying to add it there will do nothing.
Also drawing it does NOT destroy the object. You're grossly misunderstanding how any of this works. The whole POINT is that you DON'T need to create it every frame, because you can draw the same object repeatedly. What destroys the object is creating a new one and assigning it in the same slot as the previous one. This leaves the old object floating with no references to it, which will cause it to be destroyed (since the data is impossible to access). I suggest you read up on how garbage collection works if you want more information on that.
I should clarify, I literally created imagic. I know how it works, so if something you think about it seems to contradict what I'm saying, chances are you've misunderstood something.
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Tue Nov 13, 2018 7:49 pm
Thanks, it finally worked!
|
|
|
|
|
|
|
|
|
-
GforGoomba
- Rocky Wrench

- Posts: 628
- Joined: Sat May 05, 2018 11:08 am
- Flair: It... it worked...
Postby GforGoomba » Fri Nov 23, 2018 1:20 pm
Is a Super Saiyan powerup possible? As in really fast, invincible, only accessible when you have the Chaos Emeralds (or another collectible)
|
|
|
|
|
|
|
|
|
-
ztarwuff
- Cheep-Cheep

- Posts: 11
- Joined: Sun Mar 01, 2015 5:08 pm
Postby ztarwuff » Fri Nov 23, 2018 3:13 pm
Hi, there. I'm developing a level with custom music as the level's default and want to trigger custom music when a boss is encountered. I initially tried this:
Code: Select all function onEvent(BossMusic)
if BossMusic == "Bossstart" then
Audio.MusicChange(7,"boss.ogg",0)
end
end
Nothing happened. Then I came across this post: viewtopic.php?t=13295
The code didn't look right, but I tried it anyway. It's certainly doing something. The stream seizes alright, but the boss music only loads upon death.
Code: Select all play=false
function onTick()
--Start Boss Music
if play == true then
Audio.SeizeStream(7)
Audio.MusicOpen("boss.ogg")
Audio.MusicPlay()
end
--Restart Normal Music upon boss defeat
if play == false then
Audio.ReleaseStream(7)
end
end
function onEvent(BossMusic)
if BossMusic == "BossStart" then
play = true
end
if BossMusic == "BossDefeat" then
play = false
end
end
Should it be onTick as the post suggested? I don't think it should be, but upon trying onEvent, nothing happens.
Any help would be greatly appreciated.
|
|
|
|
|
|
|
|
|
-
Daring Tombstone
- Blooper

- Posts: 160
- Joined: Mon Aug 28, 2017 10:57 pm
- Flair: What? Not 1000 posts? That means I suck right?
Postby Daring Tombstone » Fri Nov 23, 2018 6:56 pm
Are you trying to have custom music, encounter a boss fight, then have another custom track start? If you're looking to use 2 custom soundtracks in the same section this can be easily done by just having a custom soundtrack onStart and having an event trigger the other custom track. So something like this should work.
Code: Select all function onStart()
Audio.MusicOpen(Misc.resolveFile("musictrack.ogg"))
Audio.MusicPlay()
end
You can also use function onLoadSection#() if you want it to start playing on a certain section as well. Be sure to set the other custom track you want to use in the editor but have it on silent and waiting. Then when the boss fight start simply have an in editor event happen that makes your other sound track start. I'm a super noob at lua myself so if this isn't what you needed my apologies. I'm sure someone with more lua experience could help you out.
Another thing you might need if you're using lua for music is to tell the game to stop playing music if the player dies. If music is started with lua and the player dies, the music doesn't stop like it normally does. At least in my experience it didn't.
EDIT: Ah wait you want the original music to start again after the boss is dead? Sorry I didn't read the second code thoroughly. I got that to work with the eventu API which comes with beta 3. We can make a code like this.
Code: Select all local eventu = API.load("eventu") --Load API
function onEvent(eventname)
if (eventname == "Dead") then --Triggers on Boss Death
eventu.run(Dead)
end
if (eventname == "Test") then --Triggers on Boss Appearance
eventu.run(Music)
end
end
function onStart()
Audio.MusicOpen(Misc.resolveFile("Aquatic Ambience.ogg")) --Music Start
Audio.MusicPlay()
end
function Music()
Audio.MusicOpen(Misc.resolveFile("Battle.ogg")) --Boss Music
Audio.MusicPlay()
end
function onTick() --Stop Music on Death
if player:mem(0x13E,FIELD_WORD) > 0 then
Audio.MusicStop()
end
end
function Dead() --Boss is Dead
Audio.MusicOpen(Misc.resolveFile("Aquatic Ambience.ogg"))
Audio.MusicPlay()
end
Pretty much the same script I used in my test level. Use it for a reference if you will. Be sure to check back when an expert on lua shows an easier way of doing this (again I'm a super noob).
Speaking of noobness, I'm trying to use the custom lotus API. I know the guy that made the API is banned and stuff but it's still an interesting API. I just can't even get it to load without a debug menu popping up. I have the customlotus png files properly in the level folder as well as that json file (I pulled from the shogun folder from the beta 3). Is there something I'm missing?
|
|
|
|
|
|
|
|
|
-
ztarwuff
- Cheep-Cheep

- Posts: 11
- Joined: Sun Mar 01, 2015 5:08 pm
Postby ztarwuff » Sat Nov 24, 2018 10:27 am
Daring Tombstone wrote: ↑Fri Nov 23, 2018 6:56 pm
EDIT: Ah wait you want the original music to start again after the boss is dead? Sorry I didn't read the second code thoroughly. I got that to work with the eventu API which comes with beta 3. We can make a code like this.
Yes, that's right. The player comes across the boss, an event triggers that changes the music from level to boss battle music. After the boss is defeated, a new event causes the boss battle music to stop and the level music to play. I just realised I was overcomplicating things. The editor already has a restore to default event, so I don't need to use LunaLua to do the latter. I just need lunalua to swap to boss music.
Code: Select all local eventu = API.load("eventu") --Load API
function onEvent(eventname)
if (eventname == "Dead") then --Triggers on Boss Death
eventu.run(Dead)
end
if (eventname == "Test") then --Triggers on Boss Appearance
eventu.run(Music)
end
end
function onStart()
Audio.MusicOpen(Misc.resolveFile("Aquatic Ambience.ogg")) --Music Start
Audio.MusicPlay()
end
function Music()
Audio.MusicOpen(Misc.resolveFile("Battle.ogg")) --Boss Music
Audio.MusicPlay()
end
function onTick() --Stop Music on Death
if player:mem(0x13E,FIELD_WORD) > 0 then
Audio.MusicStop()
end
end
function Dead() --Boss is Dead
Audio.MusicOpen(Misc.resolveFile("Aquatic Ambience.ogg"))
Audio.MusicPlay()
end
Unfortunately, this, for some reason is causing the level music to restart instead of triggering the boss battle music.
|
|
|
|
|
|
|
|
|
-
Daring Tombstone
- Blooper

- Posts: 160
- Joined: Mon Aug 28, 2017 10:57 pm
- Flair: What? Not 1000 posts? That means I suck right?
Postby Daring Tombstone » Sat Nov 24, 2018 9:14 pm
Are you sure there's no in game events that's changing the music? I had an issue with music restarting unless I started the level on silence as well as any in game event not triggering music.
|
|
|
|
|
|
|
|
|
-
GforGoomba
- Rocky Wrench

- Posts: 628
- Joined: Sat May 05, 2018 11:08 am
- Flair: It... it worked...
Postby GforGoomba » Sun Nov 25, 2018 11:52 am
Trying to make a goal post from Sonic the Hedgehog, how do I set it so it stays on the first frame onStart, plays the animation when touched (instead of killing it instantly like the axe does) and make it stay on the last frame to end the level?
|
|
|
|
|
|
|
|
|
-
ztarwuff
- Cheep-Cheep

- Posts: 11
- Joined: Sun Mar 01, 2015 5:08 pm
Postby ztarwuff » Sun Nov 25, 2018 2:13 pm
Daring Tombstone wrote: ↑Sat Nov 24, 2018 9:14 pm
Are you sure there's no in game events that's changing the music? I had an issue with music restarting unless I started the level on silence as well as any in game event not triggering music.
Ah, yes, that was it. There was an old event I didn't realise was still there. Your method is also very easy to adapt for another level I'm working on where I needed to change the music in multiple sections. Thank you so much!
|
|
|
|
|
|
|
|
|
-
Dog Gord Cat
- Goomba

- Posts: 1
- Joined: Sat Dec 01, 2018 12:11 pm
- Flair: Im fabulous
Postby Dog Gord Cat » Sat Dec 01, 2018 12:25 pm
How would I make it so a block disappears when it gets touched by a player? I'm new to lunalua : (
|
|
|
|
|
|
|
|
|
-
8lue Storm
- Volcano Lotus

- Posts: 595
- Joined: Thu Jan 18, 2018 9:53 am
- Flair: its pronounced bluestorm
Postby 8lue Storm » Sat Dec 01, 2018 12:49 pm
Dog Gord Cat wrote: ↑Sat Dec 01, 2018 12:25 pm
How would I make it so a block disappears when it gets touched by a player? I'm new to lunalua : (
You can detect player collision with a block through the function Block.collidesWith(player), if it's 0, there's no collision, 1 means the player is on top of the block, 2 means in the right, 3 means bottom and 4 means in the left. To "get" the block, you can do a for loop with Block.get.
Code: Select all function onTick()
for _,banana in ipairs(Block.get(--[id of the block])) do
if banana:collidesWith(player)~= 0 then
banana:remove(true)
end
end
end
You can name "banana" anything, as long as you write the block id instead of "--[id of the block]". The if condition that includes the function checks if it's differnt than 0, or rather, if there is any kind of collision with the player. If you set banana:remove(false) instead of banana:remove(true), you won't see the effect or hear the sound of the block breaking.
IMPORTANT LINKS
https://wohlsoft.ru/pgewiki/Block_(class)
https://wohlsoft.ru/pgewiki/How_To:_NPC ... tiple_NPCs (this one was written to be used for NPCs, but the process for blocks is almost the same.)
Hope it worked! Good luck!
|
|
|
|
|
Return to “LunaLua”
Users browsing this forum: No registered users and 2 guests
|