Re: Need help with lua? - LunaLua General Help
Posted: Thu May 05, 2016 5:37 am
Does anyone know why setting particles.lua example's "rain" to "fog" (or whatever it was) creates an error?
Forums for SMBX
https://www.smbxgame.com/forums/
Code: Select all
local bloki = { 80, 81, 82, 83, 84, 85, 86, 87, 263, 264, 265, 266, 273, 299, 300, 301, 302, 303, 304, 309, 310, 616, 617, 618, 619 }
timerApi = loadAPI("leveltimer");
local particles = API.load("particles");
local bloki1=300
local starman = loadAPI("starman")
starman.sfxFile = "sm64_star.ogg"
function onTick()
for a, b in pairs (Block.get(bloki)) do
b.slippery = true
end
for c, d in pairs (NPC.get(9,-1)) do
d.id = 185
end
bloki1=bloki1-1
if bloki1 == -301 or bloki1 < -301 then
bloki1=300
end
if bloki1 > 0 and bloki1 < 301 then
for g,h in pairs (Block.get(430)) do
h.id = 115
end
end
if bloki1 < 0 or bloki1 == 0 then
for i,j in pairs (Block.get(115)) do
j.id = 430
end
end
end
function onLoad()
timerApi.setSecondsLeft(400);
timerApi.setTimerState(true);
end
local effect = particles.Emitter(0, 0, Misc.resolveFile("particles\\p_snow.ini"));
effect:AttachToCamera(Camera.get()[1]);
function onCameraUpdate()
effect:Draw();
end
The easiest way would probably be to only execute the Draw function when you are in a specific section.Mario_and_Luigi_55 wrote:
I want to make the snowing effect to appear in 1st and 2nd section, but not in 3rd. How can I do that?
Code: Select all
function onCameraUpdate()
if(player.section == 0 or player.section == 1) then
effect:Draw();
end
end
Code: Select all
function onLoadSection0()
effect.enabled = true;
end
function onLoadSection1()
effect.enabled = true;
end
function onLoadSection2()
effect.enabled = false;
effect:KillParticles();
end
This is the better method.S1eth wrote:Code: Select all
function onCameraUpdate() if(player.section == 0 or player.section == 1) then effect:Draw(); end end
I remembered getting a similar error. I think it's because the particle folder may be missing some files (such as the "part_default.png" file). Try downloading the particles folder again, and copy everything into the LuaScriptsLib folder.Circle Guy wrote:Does anyone know why setting particles.lua example's "rain" to "fog" (or whatever it was) creates an error?
TheDinoKing432 wrote:I remembered getting a similar error. I think it's because the particle folder may be missing some files (such as the "part_default.png" file). Try downloading the particles folder again, and copy everything into the LuaScriptsLib folder.Circle Guy wrote:Does anyone know why setting particles.lua example's "rain" to "fog" (or whatever it was) creates an error?
Code: Select all
local encrypt = API.load("encrypt")
local keyData1 = encrypt.Data(Data.DATA_LEVEL, true)
local keyData2 = encrypt.Data(Data.DATA_LEVEL, true)
local keySprite = Graphics.loadImage("key sprite.png")
function onTick()
local testLayer = Layer.get("layer1")
local testLayer2 = Layer.get("layer2")
Text.print(keyData1:get("Key"),0,0)
Text.print(keyData2:get("Key2"),0,20)
if keyData1:get("Key") == 0 then
Graphics.drawImage(keySprite, 10, 100)
testLayer:hide(true)
end
if keyData2:get("Key2") == 0 then
Graphics.drawImage(keychainSprite, 10, 120)
testLayer2:hide(true)
end
end
if keyData1:get("Key") == nil then
keyData1:set("Key",1)
keyData1:save()
end
if keyData2:get("Key2") == nil then
keyData2:set("Key2",1)
keyData2:save()
end
function onEvent(eventname)
if (eventname == "test") then
keyData1:set("Key",keyData1:get("Key")-1)
keyData1:save(0)
end
if (eventname == "test2") then
keyData2:set("Key2",keyData2:get("Key2")-1)
keyData2:save(0)
end
end
zlakergirl357 wrote:I'm trying to hide a layer once an Event in SMBX is called , however one of the Data classes in the function onEvent won't save for some reason
This is your problem. I'd also recommend using colliders.collideBlock instead of using Block.get followed by a standard collide. collideBlock is a lot faster and is designed for exactly this.Spinda wrote:You're not updating the width and height of the collider.
Thanks so much! Didn't even cross my mind to do soSpinda wrote:
I'll try that. Thanks for the suggestionHoeloe wrote:
Keep in mind that the star counter is already under the lives counter, so you don't want to put the dragon coins there.PixelPest wrote:Thanks so much! Didn't even cross my mind to do soSpinda wrote:I'll try that. Thanks for the suggestionHoeloe wrote:
Also, I've seen it done before, does anyone know what the co-ordinates of where a Dragon Coin counter would lie if I put it directly below the 1-up counter? I know I could just use trial and error, but I've seen it done before and was wondering if someone could save me a bit of time. (Also, I know how to actually code the counter, I just need the co-ordinates.)
Why don't you just use v:collidesWith(player) > 0 ? http://wohlsoft.ru/pgewiki/Block_%28class%29PixelPest wrote:I'm using this code to add hurt blocks: http://hastebin.com/gerafacetu.lua
It works completely fine when the player is small, however when the player has a power-up and is big, a collision between playerBox and one of the blocks does not occur if the player is standing on a block however it does work if the player bumps one of the new hurt blocks with their head or if they touch one from the side. How can I improve this code to make it detect a collision below the player when they have a power-up?
Code: Select all
Graphics.drawImageWP(hintCoinCointer_image, 488, 68, 5);
Still won't work. Here's the entire file: http://hastebin.com/uninumelig.luaEnjl wrote:your image is nil. Maybe it's called "counter" and not "cointer"