Page 64 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Sat Feb 10, 2018 1:57 pm
by Rixitic
A lot of those tags are specifically for PGE and won't have any effect on SMBX, just the editor.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Feb 14, 2018 5:00 am
by erkyp3rky
Is it possible to make a block using LunaLua that kills off thrown items when they touch it? We all know that vegetables, when thrown, pass through walls, but I want to make a puzzle where the vegetable has to hit a certain receptacle while avoiding "No-Vegetable" blocks.

Which leads me to my second question, is it possible to use LunaLua to make it so that when you throw a vegetable at a switch block it activates? Thanks!

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 06, 2018 4:43 pm
by ElectriKong
Does anyone know how to disable the ability to jump (all types)?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 06, 2018 4:50 pm
by Taycamgame
Electriking wrote:Does anyone know how to disable the ability to jump (all types)?
https://wohlsoft.ru/pgewiki/How_To:_Ove ... ayer_input
I haven't tried it myself, but:
I think you need to look at the part called "Disable Spin Jump". Copy that code into your lunadll file but instead of saying altJumpKeyPressing just put JumpKeyPressing.
Idk if this would work but logically it should.
function onInputUpdate()
if(player.JumpKeyPressing) then
player.JumpKeyPressing = false;
end
end

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 06, 2018 7:59 pm
by PixelPest
Taycamgame wrote:
Electriking wrote:Does anyone know how to disable the ability to jump (all types)?
https://wohlsoft.ru/pgewiki/How_To:_Ove ... ayer_input
I haven't tried it myself, but:
I think you need to look at the part called "Disable Spin Jump". Copy that code into your lunadll file but instead of saying altJumpKeyPressing just put JumpKeyPressing.
Idk if this would work but logically it should.
function onInputUpdate()
if(player.JumpKeyPressing) then
player.JumpKeyPressing = false;
end
end
Try using code tags (also shows the indentation):

Code: Select all

[code]
[/code]

Also you don't even need to check for it and if you want to add no spinjumping either:

Code: Select all

function onInputUpdate()
    player.jumpKeyPressing = false;
    player.altJumpKeyPressing = false;
end 

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 06, 2018 11:53 pm
by erkyp3rky
PixelPest wrote:
Taycamgame wrote:
Electriking wrote:Does anyone know how to disable the ability to jump (all types)?
https://wohlsoft.ru/pgewiki/How_To:_Ove ... ayer_input
I haven't tried it myself, but:
I think you need to look at the part called "Disable Spin Jump". Copy that code into your lunadll file but instead of saying altJumpKeyPressing just put JumpKeyPressing.
Idk if this would work but logically it should.
function onInputUpdate()
if(player.JumpKeyPressing) then
player.JumpKeyPressing = false;
end
end
Try using code tags (also shows the indentation):

Code: Select all

[code]
[/code]

Also you don't even need to check for it and if you want to add no spinjumping either:

Code: Select all

function onInputUpdate()
    player.jumpKeyPressing = false;
    player.altJumpKeyPressing = false;
end 
Any idea how to make vegetable blocking blocks as I mentioned earlier?

Re: Need help with lua? - LunaLua General Help

Posted: Wed Mar 07, 2018 3:22 am
by Taycamgame
PixelPest wrote:

Code: Select all

function onInputUpdate()
    player.jumpKeyPressing = false;
    player.altJumpKeyPressing = false;
end 
Looks more simple, guess i almost had it. But doesn't that code run every time the player presses any key (including the arrow keys)? I thought the function OnInputUpdate checks for every key press, and to limit it to one key you use if?

Re: Need help with lua? - LunaLua General Help

Posted: Wed Mar 07, 2018 4:48 am
by Hoeloe
onInputUpdate runs every frame, not every time you press a key. And even if that were the case, a condition inside the function definition wouldn't stop the function from running.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Mar 30, 2018 10:05 pm
by Nonlen17
How do I make it so the image I load with Graphics.loadImage when an certain event activates will not disappear the next frame?

Re: Need help with lua? - LunaLua General Help

Posted: Fri Mar 30, 2018 10:30 pm
by PixelPest
Nonlen17 wrote:How do I make it so the image I load with Graphics.loadImage when an certain event activates will not disappear the next frame?
I'd suggest approaching it like this:

Code: Select all

local hasTriggered = false;

local myImg = Graphics.loadImage("myImg");

function onEvent(eventname)
    if eventname == "myEvent" then
        hasTriggered = true;
    end
end

function onDraw()
    if hasTriggered then
        --draw the image here
    end
end
Set a variable that represents the state as to whether or not your event has been triggered (hasTriggered), initially being false. Also load your image at the start and set it as a variable (myImg). Then in your onEvent if the eventname is the one you're looking for set the variable hasTriggered to true. In your onDraw (this runs every frame) check if hasTriggered is true (if hasTriggered then) and then draw your image (myImg).

Since you said it's appearing for one frame I assumed you have the line already for drawing the code so I didn't include one. If you have any questions about anything in the code feel free to ask and I can explain it better if needed

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 03, 2018 4:44 pm
by WildW
How can I make an NPC that is spawned using NPC.spawn face the direction that the player is facing when spawned?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 03, 2018 4:55 pm
by PixelPest
WildWEEGEE wrote:How can I make an NPC that is spawned using NPC.spawn face the direction that the player is facing when spawned?
NPC.spawn returns the NPC object. You can then immediately set it's direction field to player:mem(0x106, FIELD_WORD)

Re: Need help with lua? - LunaLua General Help

Posted: Tue Apr 03, 2018 5:24 pm
by WildW
PixelPest wrote:
WildWEEGEE wrote:How can I make an NPC that is spawned using NPC.spawn face the direction that the player is facing when spawned?
NPC.spawn returns the NPC object. You can then immediately set it's direction field to player:mem(0x106, FIELD_WORD)
I don't know where I can place this piece of code...

this is the script I'm using:

Code: Select all

function onKeyDown(keycode)
    if keycode == KEY_RUN then
	a = NPC.spawn(108,player.x,player.y - 48,player.section)
	a.speedX = -6;
    end

end
It's WIP but so far it can only spawn the object facing left.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Apr 04, 2018 1:15 am
by erkyp3rky
PixelPest wrote:
WildWEEGEE wrote:How can I make an NPC that is spawned using NPC.spawn face the direction that the player is facing when spawned?
NPC.spawn returns the NPC object. You can then immediately set it's direction field to player:mem(0x106, FIELD_WORD)
Hey Pixel, is there anyway to block vegetables (Or throw-able items in general) with a line of code which can be applied to a block?

P.S: Nice profile picture ;)

Re: Need help with lua? - LunaLua General Help

Posted: Wed Apr 04, 2018 1:32 am
by WildW
The_Loaf_Lord wrote:
PixelPest wrote:
WildWEEGEE wrote:How can I make an NPC that is spawned using NPC.spawn face the direction that the player is facing when spawned?
NPC.spawn returns the NPC object. You can then immediately set it's direction field to player:mem(0x106, FIELD_WORD)
Hey Pixel, is there anyway to block vegetables (Or throw-able items in general) with a line of code which can be applied to a block?

P.S: Nice profile picture ;)
How long have you been searching for the answer to that? Months? All of your posts have been ignored... anyway
TheLoafLord wrote:is it possible to use LunaLua to make it so that when you throw a vegetable at a switch block it activates?
I can answer your second question just not your first. To achieve this you can have an NPC that looks like a switch block placed where the switch would be. When the NPC is killed by a vegetable it will trigger an event that spawns a new switch block NPC in the same place plus turn those switch blockers into the pass-through able backgrounds, vice versa.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Apr 04, 2018 1:34 am
by erkyp3rky
WildWEEGEE wrote:
The_Loaf_Lord wrote:
PixelPest wrote: NPC.spawn returns the NPC object. You can then immediately set it's direction field to player:mem(0x106, FIELD_WORD)
Hey Pixel, is there anyway to block vegetables (Or throw-able items in general) with a line of code which can be applied to a block?

P.S: Nice profile picture ;)
How long have you been searching for the answer to that? Months? All of your posts have been ignored... anyway
TheLoafLord wrote:is it possible to use LunaLua to make it so that when you throw a vegetable at a switch block it activates?
I can answer your second question just not your first. To achieve this you can have an NPC that looks like a switch block placed where the switch would be. When the NPC is killed by a vegetable it will trigger an event that spawns a new switch block NPC in the same place plus turn those switch blockers into the pass-through able backgrounds, vice versa.
Ah, I got one answer! Thank you!

Re: Need help with lua? - LunaLua General Help

Posted: Wed Apr 04, 2018 1:41 am
by WildW
No problem ;)

Re: Need help with lua? - LunaLua General Help

Posted: Wed Apr 04, 2018 5:37 am
by Taycamgame
The_Loaf_Lord wrote:Is it possible to make a block using LunaLua that kills off thrown items when they touch it? We all know that vegetables, when thrown, pass through walls, but I want to make a puzzle where the vegetable has to hit a certain receptacle while avoiding "No-Vegetable" blocks.
I haven't tried it myself, but perhaps lava could work in this situation? Just reskin it to make it look like the blocks you need.
If that doesn't work, then maybe you would have to make the npc hit blocks? What i mean is, try putting this code in your npc text file:

Code: Select all

noblockcollision=0
What this does is make it so that the NPC will not actually go through blocks. This may not be exactly what you wanted, but it's the best i can offer i'm afraid.
Hope i could help!

Re: Need help with lua? - LunaLua General Help

Posted: Wed Apr 04, 2018 5:41 am
by Emral
Vegetables already have block collision. That's how they don't fall through the ground when simply placed.

Re: Need help with lua? - LunaLua General Help

Posted: Wed Apr 04, 2018 6:59 am
by erkyp3rky
Enjl wrote:Vegetables already have block collision. That's how they don't fall through the ground when simply placed.
Yes but when throwing them, they pass right through blocks.