Page 20 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Thu May 05, 2016 5:37 am
by Circle Guy
Does anyone know why setting particles.lua example's "rain" to "fog" (or whatever it was) creates an error?

Re: Need help with lua? - LunaLua General Help

Posted: Thu May 05, 2016 5:49 am
by Emral
No it does not it you're doing it right. Please describe the error you're having and how you're trying to load the ini. Also take a look at the particles.lua documentation because there's an example given there.
Just saying "there is an error" doesn't help anyone.

Re: Need help with lua? - LunaLua General Help

Posted: Fri May 06, 2016 9:28 am
by Mario_and_Luigi_55

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
I want to make the snowing effect to appear in 1st and 2nd section, but not in 3rd. How can I do that?

Re: Need help with lua? - LunaLua General Help

Posted: Fri May 06, 2016 1:07 pm
by S1eth
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?
The easiest way would probably be to only execute the Draw function when you are in a specific section.

Code: Select all

function onCameraUpdate()
	if(player.section == 0 or player.section == 1) then 
		effect:Draw();
	end
end
When I was looking through the code of one of Pyro's levels, I saw another method, in which she disabled the effect whenever you load another section, and enable it when you enter the section you want it in.

Code: Select all

function onLoadSection0()
	effect.enabled = true;
end

function onLoadSection1()
	effect.enabled = true;
end

function onLoadSection2()
	effect.enabled = false;
	effect:KillParticles();
end

Re: Need help with lua? - LunaLua General Help

Posted: Fri May 06, 2016 1:31 pm
by Hoeloe
S1eth wrote:

Code: Select all

function onCameraUpdate()
	if(player.section == 0 or player.section == 1) then 
		effect:Draw();
	end
end
This is the better method.

Re: Need help with lua? - LunaLua General Help

Posted: Fri May 06, 2016 1:47 pm
by TDK
Circle Guy wrote:Does anyone know why setting particles.lua example's "rain" to "fog" (or whatever it was) creates an error?
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 2:15 am
by Mario_and_Luigi_55
TheDinoKing432 wrote:
Circle Guy wrote:Does anyone know why setting particles.lua example's "rain" to "fog" (or whatever it was) creates an error?
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.

Or you can have outdated lua

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 8:25 am
by zlaker
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.

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

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 8:29 am
by Emral
Why do you have multiple data class objects? You can save everything into one file.

Also, it's just keyData1:save()

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 8:56 am
by Hoeloe
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

I suggest actually reading the documentation and looking at the examples:

http://wohlsoft.ru/pgewiki/Encrypt.dll

It's very clear on there that encrypt.Data requires 3 arguments, not 2. One of those is the filename you want to save to. Your issue is that you have two filenames that are the same (you'll actually end up saving to a file called "true").

And as has been said before, the Data class is there to save some set of data, you don't need a new one for every variable. Each new data class is a new data file, but each data file can contain as many variables as you like.

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 9:43 am
by PixelPest
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?

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 9:47 am
by underFlo
You're not updating the width and height of the collider.

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 9:55 am
by Hoeloe
Spinda wrote:You're not updating the width and height of the collider.
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 10:30 am
by PixelPest
Spinda wrote:
Thanks so much! Didn't even cross my mind to do so
Hoeloe wrote:
I'll try that. Thanks for the suggestion

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.)

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 10:32 am
by Emral
You take a screenshot, open it in any image editing software and select the top left pixel where you want the counter to be?

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 10:39 am
by S1eth
PixelPest wrote:
Spinda wrote:
Thanks so much! Didn't even cross my mind to do so
Hoeloe wrote:
I'll try that. Thanks for the suggestion

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.)
Keep in mind that the star counter is already under the lives counter, so you don't want to put the dragon coins there.
I'm using x = 218, y = 6 (I put it above the lives counter)
PixelPest 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?
Why don't you just use v:collidesWith(player) > 0 ? http://wohlsoft.ru/pgewiki/Block_%28class%29

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 6:37 pm
by PixelPest
I'm getting the error "no matching overload candidates found" with the following line, but I don't see anything wrong with it:

Code: Select all

Graphics.drawImageWP(hintCoinCointer_image, 488, 68, 5);
Any ideas? I'm really confused at why this doesn't work

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 6:37 pm
by Emral
your image is nil. Maybe it's called "counter" and not "cointer"

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 6:39 pm
by PixelPest
Enjl wrote:your image is nil. Maybe it's called "counter" and not "cointer"
Still won't work. Here's the entire file: http://hastebin.com/uninumelig.lua

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 07, 2016 6:42 pm
by Emral
does "hint-coin-counter.png" exist?