Page 71 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Wed Nov 07, 2018 7:50 pm
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Nov 07, 2018 8:07 pm
by Novarender
How exactly can I do that? I don't really know how this code works, it's just a mod of nsmbwalls.lua.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Nov 08, 2018 1:20 am
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Nov 08, 2018 8:37 am
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Nov 08, 2018 5:12 pm
by Novarender
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?

Re: Need help with lua? - LunaLua General Help

Posted: Fri Nov 09, 2018 2:24 pm
by Hoeloe
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).

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 10, 2018 9:33 am
by Novarender
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)?

Re: Need help with lua? - LunaLua General Help

Posted: Sun Nov 11, 2018 11:00 pm
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Nov 13, 2018 5:31 pm
by Novarender
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Nov 13, 2018 7:14 pm
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Nov 13, 2018 7:49 pm
by Novarender
Thanks, it finally worked!

Re: Need help with lua? - LunaLua General Help

Posted: Fri Nov 23, 2018 1:20 pm
by GforGoomba
Is a Super Saiyan powerup possible? As in really fast, invincible, only accessible when you have the Chaos Emeralds (or another collectible)

Re: Need help with lua? - LunaLua General Help

Posted: Fri Nov 23, 2018 3:13 pm
by ztarwuff
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.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Nov 23, 2018 6:56 pm
by Daring Tombstone
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?

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 24, 2018 10:27 am
by ztarwuff
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Nov 24, 2018 9:14 pm
by Daring Tombstone
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Nov 25, 2018 11:52 am
by GforGoomba
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?

Re: Need help with lua? - LunaLua General Help

Posted: Sun Nov 25, 2018 2:13 pm
by ztarwuff
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!

Re: Need help with lua? - LunaLua General Help

Posted: Sat Dec 01, 2018 12:25 pm
by Dog Gord Cat
How would I make it so a block disappears when it gets touched by a player? I'm new to lunalua : (

Re: Need help with lua? - LunaLua General Help

Posted: Sat Dec 01, 2018 12:49 pm
by 8lue Storm
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!