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?
PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Tue Feb 14, 2017 10:32 pm

Code: Select all

function onMessageBox(eventObj, msgStr)
   if msgStr == "CutsceneTalk1" then
      eventObj.cancelled == true
      Text.showMessageBox("MosaicMario: Great job guys! We made it through the fortress!")
      Text.showMessageBox("Rosy: I wonder why there were so many ninjis in there?")
      elseif msgStr == "CutsceneTalk2" then
      eventObj.cancelled == true
      Text.showMessageBox("Hoops: Hey guys, look at this bridge! Where could it lead?")
      Text.showMessageBox("Berry: Yoshi!(I don't know, but i'm curious too!)")
      Text.showMessageBox("MosaicMario: Hoops, I think that maybe you should slow dow-")
      Text.showMessageBox("Hoops: Last one to the other side's a rotton mushroom!")
      elseif msgStr == "CutsceneTalk3" then
      eventObj.cancelled == true
      Text.showMessageBox("MosaicMario: Hoops! Wait up!")
      elseif msgStr == "CutsceneTalk4" then
      eventObj.cancelled == true
      Text.showMessageBox("Rosy:...Well, what do you say Berry? Should we catch up with them?")
      Text.showMessageBox("Berry: Yoshi!(Yeah, sure!)")
      Text.showMessageBox("Rosy: Let's go catch them i guess.")
   end
end
Here it is.

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 » Tue Feb 14, 2017 10:35 pm

Remember (basic Lua, you really need to read a tutorial since you lack even the essentials): two equal signs for comparing, one for declaring. eventObj.cancelled == true will error every time because of this

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Tue Feb 14, 2017 10:39 pm

Now i ran into a new problem, it loops the text. How do i fix this?
Here's the New Code by the way:

Code: Select all

function onMessageBox(eventObj, msgStr)
   if msgStr == "CutsceneTalk1" then
      eventObj.cancelled = true
      Text.showMessageBox("MosaicMario: Great job guys! We made it through the fortress!")
      Text.showMessageBox("Rosy: I wonder why there were so many ninjis in there?")
	  elseif msgStr == "CutsceneTalk2" then
	  eventObj.cancelled = true
	  Text.showMessageBox("Hoops: Hey guys, look at this bridge! Where could it lead?")
	  Text.showMessageBox("Berry: Yoshi!(I don't know, but i'm curious too!)")
	  Text.showMessageBox("MosaicMario: Hoops, I think that maybe you should slow dow-")
	  Text.showMessageBox("Hoops: Last one to the other side's a rotton mushroom!")
	  elseif msgStr == "CutsceneTalk3" then
	  eventObj.cancelled = true
	  Text.showMessageBox("MosaicMario: Hoops! Wait up!")
      elseif msgStr == "CutsceneTalk4" then
	  eventObj.cancelled = true
	  Text.showMessageBox("Rosy:...Well, what do you say Berry? Should we catch up with them?")
      Text.showMessageBox("Berry: Yoshi!(Yeah, sure!)")
	  Text.showMessageBox("Rosy: Let's go catch them i guess.")
   end
end   

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Thu Feb 16, 2017 9:49 pm

Actually, i have a different question, is there a function that puts an item into your inventory? i basically mean ANY item or npc can be put into your inventory.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Thu Feb 16, 2017 10:27 pm


PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Fri Feb 17, 2017 3:41 am

i messed up my encrypt file because i downloaded the latest version, how do i fix this?

DeMuZ
Fighter Fly
Fighter Fly
Posts: 37
Joined: Thu Aug 18, 2016 2:35 pm

Re: Need help with lua? - LunaLua General Help

Postby DeMuZ » Fri Feb 17, 2017 9:53 am

Is there any function which returns the number of the save slot? :v

Devan2002
Chain Chomp
Chain Chomp
Posts: 304
Joined: Sun Oct 02, 2016 9:46 am

Re: Need help with lua? - LunaLua General Help

Postby Devan2002 » Fri Feb 17, 2017 4:42 pm

Enjl wrote:
Devan2002 wrote:
Devan2002 wrote:How would I change the sound effects with LunaLua? I do have it downloaded.
Enjl wrote:ini_examples folder. There's a sounds.ini file. Copy into your level/worlds folder and change directories. Directories are relative to the folder sounds.ini is in.
I couldn't find the folder ini_examples with the sounds.ini file. I have LunaLua version 0.7.3 beta update. Do I need to download a certain version of LunaLua for it to work?
Image
Image
I can guarantee that it is in 2.0. I don't know if it's in the LunaLua download.
Am I able to take certain folders and files from the lunalua you have in the image you posted into the lunalua I have (that don't involve things like PGE)? Or will that not work?

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Fri Feb 17, 2017 8:27 pm

Can someone help me with this?(I know i ask alot)
I'm trying make my own custom made money system, i put in this code:

Code: Select all

local encrypt = API.load("encrypt")
local CoinData = encrypt.Data(Data.DATA_LEVEL, true)
local CoinCount = 0;

if CoinData:get("CoinCount") == nil then
	CoinData:set("CoinCount",1)
	CoinData:save()
 end
 
function OnTick()
	Text.print(CoinData:get("CoinCount"),0,0)
 end
 
function onEvent(eventname)
	if eventname == "hit" then
		CoinData:set("CoinCount",CoinData:get("CoinCount")+1)
		CoinData:save(0)
	end
end

function onLoad()
  img = Graphics.loadImage("coincounter.png")
  Graphics.placeSprite(1, img, 500, 50)
end

function onNPCKill(eventObj,npcID)
	if npcID.id == 10 then
		 CoinData:set("CoinCount", CoinData:get("CoinCount")+1)
		 CoinData:save(0) elseif
	   npcID.id == 33 then
		 CoinData:set("CoinCount", CoinData:get("CoinCount")+1)
		 CoinData:save(0) elseif
	   npcID.id == 88 then
		 CoinData:set("CoinCount", CoinData:get("CoinCount")+1)
		 CoinData:save(0) elseif
	   npcID.id == 138 then
	     CoinData:set("CoinCount", CoinData:get("CoinCount")+1)
		 CoinData:save(0) elseif 
	   npcID.id == 152 then
	     CoinData:set("CoinCount", CoinData:get("CoinCount")+1)
		 CoinData:save(0) elseif
	   npcID.id == 251 then
		 CoinData:set("CoinCount", CoinData:get("CoinCount")+1)
		 CoinData:save(0) elseif
	   npcID.id == 252 then
		 CoinData:set("CoinCount", CoinData:get("CoinCount")+5)
		 CoinData:save(0) elseif
	   npcID.id == 253 then
		 CoinData:set("CoinCount", CoinData:get("CoinCount")+20)
		 CoinData:save(0) 
	end
end
But the text didn't show up, what do i do to fix this?

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Sun Feb 19, 2017 2:46 am

Umm, how do i fix these?
Spoiler: show
Image
Image

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 » Sun Feb 19, 2017 6:07 am

The errors tell you exactly what's wrong. After the path at the top it gives you the line number of the error. For the first one it's 14 in SuperJump.lua. Thr variable "jumpChecker" is nil and you are attempting to call it. The 2nd message is similar, but this time you're trying to perform arithmetic (do math) with a nil variable.

Angelus
Tweeter
Tweeter
Posts: 132
Joined: Tue Jun 21, 2016 9:38 am

Re: Need help with lua? - LunaLua General Help

Postby Angelus » Sun Feb 19, 2017 9:49 am

How do I create a looped layer movement with LunaLua? For example, I want a layer to move up and down, but I don't want to use the default events of the editor. I suppose I must create some kind of timer, but what kind, exactly?

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 » Sun Feb 19, 2017 9:57 am

It'd be much easier to do it with events, but if you really wanted to do it in LunaLua, you would set a variable to a layer object (which you would get from the constructor function Layer(#), where # is the layer number counting up from 0, which is the default layer). Then you would use Layer.speedY to change the speed values. You would have to set a counter that counts up and after a value that is divisible by a certain number, multiply by -1 to change the direction

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Sun Feb 19, 2017 4:11 pm

PixelPest wrote:It'd be much easier to do it with events, but if you really wanted to do it in LunaLua, you would set a variable to a layer object (which you would get from the constructor function Layer(#), where # is the layer number counting up from 0, which is the default layer). Then you would use Layer.speedY to change the speed values. You would have to set a counter that counts up and after a value that is divisible by a certain number, multiply by -1 to change the direction
A word of warning: last I checked, trying to set a layer's speed to 0 with lua will cause its objects to keep moving at a rate of around 0.0001, about a pixel every 2.5 minutes. The only reliable way I know of is to call an event that stops the layer.

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 » Sun Feb 19, 2017 5:56 pm

There's also Layer:stop()

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Sun Feb 19, 2017 6:19 pm

I had the same problem with that.

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Sun Feb 19, 2017 6:24 pm

Enjl wrote:The errors tell you exactly what's wrong. After the path at the top it gives you the line number of the error. For the first one it's 14 in SuperJump.lua. Thr variable "jumpChecker" is nil and you are attempting to call it. The 2nd message is similar, but this time you're trying to perform arithmetic (do math) with a nil variable.
The red birdo code that i'm using for some reason doesn't work correctly, i wouldn't know how to fix it.

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 » Sun Feb 19, 2017 6:28 pm

MosaicMario wrote:
Enjl wrote:The errors tell you exactly what's wrong. After the path at the top it gives you the line number of the error. For the first one it's 14 in SuperJump.lua. Thr variable "jumpChecker" is nil and you are attempting to call it. The 2nd message is similar, but this time you're trying to perform arithmetic (do math) with a nil variable.
The red birdo code that i'm using for some reason doesn't work correctly, i wouldn't know how to fix it.
If you don't post the code or even give us a vague sense of what's wrong, there's no way we can help (unless you're referring to the issues above, which basically is saying that you're trying to call a function that doesn't exist or hasn't been set to anything and trying to perform an operation on a variable that doesn't exist or hasn't been set to anything)

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Sun Feb 19, 2017 9:22 pm

PixelPest wrote:
MosaicMario wrote:
Enjl wrote:The errors tell you exactly what's wrong. After the path at the top it gives you the line number of the error. For the first one it's 14 in SuperJump.lua. Thr variable "jumpChecker" is nil and you are attempting to call it. The 2nd message is similar, but this time you're trying to perform arithmetic (do math) with a nil variable.
The red birdo code that i'm using for some reason doesn't work correctly, i wouldn't know how to fix it.
If you don't post the code or even give us a vague sense of what's wrong, there's no way we can help (unless you're referring to the issues above, which basically is saying that you're trying to call a function that doesn't exist or hasn't been set to anything and trying to perform an operation on a variable that doesn't exist or hasn't been set to anything)
Let me clarify, i didn't write this code:

Code: Select all

function onLoop()
  tableOfBirdo = NPC.get(39, -1);
  tableOfBirdoEggs = NPC.get(40, -1);
  if(tableOfBirdo[1] ~= nil) then
    if(tonumber(tableOfBirdo[1]:mem(0xF0, FIELD_DFLOAT)) == 1) then
	  frameCount = frameCount + 1;
      if(hasGenerated ~= true) then
        ran = math.random(0, 2);
        hasGenerated = true;
      end
      if(ran == 2) then
        if(table.getn(tableOfBirdoEggs) > 0) then --checks if eggs exist
			if(frameCount > 21) then
				tableOfBirdoEggs = NPC.get(40, -1); --update table
				if(hasTransformed == false) then
					tableOfBirdoEggs[table.getn(tableOfBirdoEggs)]:mem(0xE2, FIELD_WORD, 282); --modification
					playSFX(42); --big fireball
					hasTransformed = true; --so we don't re-transform anything else
				end
			end
        end
      end
    end
    if(tonumber(tableOfBirdo[1]:mem(0xF8, FIELD_DFLOAT)) == 280) then
      hasGenerated = false; --just reset everything
	  hasTransformed = false;
	  frameCount = 0;
    end
  end
end
Since i didn't write it, i don't know how to fix it.
The thing that's wrong is that the moment the red birdo fires, the second error message comes up and then it only shoots eggs.

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 » Sun Feb 19, 2017 10:19 pm

As I set before, you have a variable that isn't set to anything at the start such that it is nil. You need to add local frameCount = 0; to the very top (as the first line). Also use onTick() instead of onLoop(). And also, you should really only use code if you understand it and therefore look through the code and learn what it's doing. This is a pretty simple fix.

It's not great code though and has multiple bugs. I'd suggest not using it


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari