Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.
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?
PixelPest
Link
Link
Posts: 7116
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:22 pm

Post your code here again

User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2850
Joined: Fri Feb 27, 2015 8:07 pm
Flair: All has a reason behind it, even if it's tough.
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Mosaic » 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.

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord Server, where I update on my streams, writing, and anything else I may be up to.

Cancelled...but not forgotten...
Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image


PixelPest
Link
Link
Posts: 7116
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

User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2850
Joined: Fri Feb 27, 2015 8:07 pm
Flair: All has a reason behind it, even if it's tough.
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Mosaic » 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   

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord Server, where I update on my streams, writing, and anything else I may be up to.

Cancelled...but not forgotten...
Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image


User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2850
Joined: Fri Feb 27, 2015 8:07 pm
Flair: All has a reason behind it, even if it's tough.
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Mosaic » 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.

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord Server, where I update on my streams, writing, and anything else I may be up to.

Cancelled...but not forgotten...
Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image


User avatar
Quantumenace
Ripper II
Ripper II
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


User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2850
Joined: Fri Feb 27, 2015 8:07 pm
Flair: All has a reason behind it, even if it's tough.
Contact:

Re: Need help with lua? - LunaLua General Help

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

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

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord Server, where I update on my streams, writing, and anything else I may be up to.

Cancelled...but not forgotten...
Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image


User avatar
DeMuZ
Bob-omb
Bob-omb
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

User avatar
Devan2002
Ripper II
Ripper II
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?
It's kinda sad to see that there aren't many episodes based on Link being the main protagonist. Hopefully I can see more in the future, because LoZ was one of my favorite franchises. ;)
Image

You can always give me ideas on my projects, so don't hold them in.

I am the nerd of video games. :ugeek:
What is my life: show
Image
Supported Projects: show
Image
ImageImage
I support these projects. :mrgreen:
Also, have an adorable image of Budew.
Image
Legend of Zelda X: My project: show
Image

User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2850
Joined: Fri Feb 27, 2015 8:07 pm
Flair: All has a reason behind it, even if it's tough.
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Mosaic » 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?

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord Server, where I update on my streams, writing, and anything else I may be up to.

Cancelled...but not forgotten...
Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image


User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2850
Joined: Fri Feb 27, 2015 8:07 pm
Flair: All has a reason behind it, even if it's tough.
Contact:

Re: Need help with lua? - LunaLua General Help

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

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

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord Server, where I update on my streams, writing, and anything else I may be up to.

Cancelled...but not forgotten...
Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image


Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8737
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » 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.
Ideas are useless if you can't make them real.
Image

User avatar
Angelus
Bit
Bit
Posts: 129
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: 7116
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

User avatar
Quantumenace
Ripper II
Ripper II
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: 7116
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()

User avatar
Quantumenace
Ripper II
Ripper II
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.

User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2850
Joined: Fri Feb 27, 2015 8:07 pm
Flair: All has a reason behind it, even if it's tough.
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Mosaic » 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.

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord Server, where I update on my streams, writing, and anything else I may be up to.

Cancelled...but not forgotten...
Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image


PixelPest
Link
Link
Posts: 7116
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)

User avatar
Mosaic
Ludwig von Koopa
Ludwig von Koopa
Posts: 2850
Joined: Fri Feb 27, 2015 8:07 pm
Flair: All has a reason behind it, even if it's tough.
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Mosaic » 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.

I believe in Jesus Christ as my Lord and Savior. If you do, put this in your signature.
And Here's The Proof
My Rainbow Of Levels
Mosaic's Museum(My Discord Server, where I update on my streams, writing, and anything else I may be up to.

Cancelled...but not forgotten...
Image

Image

Danny wrote:Here's some constructive criticism: What the hell.
Witchking wrote:Approved!

Discord Quotes: show
Image



Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 2 guests