Page 47 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Tue Feb 14, 2017 10:32 pm
by PersonNamedUser

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.

Re: Need help with lua? - LunaLua General Help

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

Re: Need help with lua? - LunaLua General Help

Posted: Tue Feb 14, 2017 10:39 pm
by PersonNamedUser
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   

Re: Need help with lua? - LunaLua General Help

Posted: Thu Feb 16, 2017 9:49 pm
by PersonNamedUser
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.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Feb 16, 2017 10:27 pm
by Quantumenace

Re: Need help with lua? - LunaLua General Help

Posted: Fri Feb 17, 2017 3:41 am
by PersonNamedUser
i messed up my encrypt file because i downloaded the latest version, how do i fix this?

Re: Need help with lua? - LunaLua General Help

Posted: Fri Feb 17, 2017 9:53 am
by DeMuZ
Is there any function which returns the number of the save slot? :v

Re: Need help with lua? - LunaLua General Help

Posted: Fri Feb 17, 2017 4:42 pm
by Devan2002
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?

Re: Need help with lua? - LunaLua General Help

Posted: Fri Feb 17, 2017 8:27 pm
by PersonNamedUser
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?

Re: Need help with lua? - LunaLua General Help

Posted: Sun Feb 19, 2017 2:46 am
by PersonNamedUser
Umm, how do i fix these?
Spoiler: show
Image
Image

Re: Need help with lua? - LunaLua General Help

Posted: Sun Feb 19, 2017 6:07 am
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Feb 19, 2017 9:49 am
by Angelus
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?

Re: Need help with lua? - LunaLua General Help

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

Re: Need help with lua? - LunaLua General Help

Posted: Sun Feb 19, 2017 4:11 pm
by Quantumenace
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Feb 19, 2017 5:56 pm
by PixelPest
There's also Layer:stop()

Re: Need help with lua? - LunaLua General Help

Posted: Sun Feb 19, 2017 6:19 pm
by Quantumenace
I had the same problem with that.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Feb 19, 2017 6:24 pm
by PersonNamedUser
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Feb 19, 2017 6:28 pm
by PixelPest
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)

Re: Need help with lua? - LunaLua General Help

Posted: Sun Feb 19, 2017 9:22 pm
by PersonNamedUser
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.

Re: Need help with lua? - LunaLua General Help

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