Need help with lua? - LunaLua General Help

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?
Circle Guy
Rocky Wrench
Rocky Wrench
Posts: 645
Joined: Mon Jan 04, 2016 9:25 pm

Re: Need help with lua? - LunaLua General Help

Postby Circle Guy » 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?

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Thu May 05, 2016 5:49 am

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.

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Fri May 06, 2016 9:28 am

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?

S1eth
Bot
Bot
Posts: 54
Joined: Sat Apr 23, 2016 10:44 am

Re: Need help with lua? - LunaLua General Help

Postby S1eth » Fri May 06, 2016 1:07 pm

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
Last edited by S1eth on Fri May 06, 2016 2:17 pm, edited 1 time in total.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Fri May 06, 2016 1:31 pm

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.

TDK
Phanto
Phanto
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Need help with lua? - LunaLua General Help

Postby TDK » Fri May 06, 2016 1:47 pm

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.

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Sat May 07, 2016 2:15 am

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

zlaker
Reznor
Reznor
Posts: 2844
Joined: Fri Dec 20, 2013 1:46 pm

Re: Need help with lua? - LunaLua General Help

Postby zlaker » Sat May 07, 2016 8:25 am

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

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sat May 07, 2016 8:29 am

Why do you have multiple data class objects? You can save everything into one file.

Also, it's just keyData1:save()

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sat May 07, 2016 8:56 am

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.

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sat May 07, 2016 9:43 am

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?

underFlo
Wart
Wart
Posts: 4456
Joined: Mon Jul 14, 2014 10:44 am
Flair: sup im lesbiab
Pronouns: They/She
Contact:

Re: Need help with lua? - LunaLua General Help

Postby underFlo » Sat May 07, 2016 9:47 am

You're not updating the width and height of the collider.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sat May 07, 2016 9:55 am

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.

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sat May 07, 2016 10:30 am

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

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sat May 07, 2016 10:32 am

You take a screenshot, open it in any image editing software and select the top left pixel where you want the counter to be?

S1eth
Bot
Bot
Posts: 54
Joined: Sat Apr 23, 2016 10:44 am

Re: Need help with lua? - LunaLua General Help

Postby S1eth » Sat May 07, 2016 10:39 am

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

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sat May 07, 2016 6:37 pm

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

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sat May 07, 2016 6:37 pm

your image is nil. Maybe it's called "counter" and not "cointer"

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sat May 07, 2016 6:39 pm

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

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sat May 07, 2016 6:42 pm

does "hint-coin-counter.png" exist?


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari