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?
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 » Tue Apr 05, 2016 1:20 am

API.load is pretty much the same as loadSharedAPI afaik, except you can also make it work like loadAPI if you set a bool as the argument (even though I don't recall what it was exactly).

The main reason API.load is preferred is cleaner code - optimally, all the functions should either be methods, defined in the script itself or inside of a table that is loaded by default. That's why functions likely getNPC are deprecated.

Zeus guy
Spiny
Spiny
Posts: 26
Joined: Fri Dec 20, 2013 12:46 pm

Re: Need help with lua? - LunaLua General Help

Postby Zeus guy » Tue Apr 05, 2016 2:34 pm

Ok so it's me again yay.
After some hours of frustration and not getting anything done, I decided to stop coding and start... coding something else. So I remembered something I read on this thread:
Hoeloe wrote:3) When in the reversed section, apply some code using LunaLua's Capture Buffers to flip the screen upside down.
Now I've spent some time searching on google and the only thing I've found is that it wasn't possible 5 months ago. So, is it possible now? And if that's the case, how?

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 Apr 05, 2016 10:40 pm

Zeus guy wrote:Ok so it's me again yay.
After some hours of frustration and not getting anything done, I decided to stop coding and start... coding something else. So I remembered something I read on this thread:
Hoeloe wrote:3) When in the reversed section, apply some code using LunaLua's Capture Buffers to flip the screen upside down.
Now I've spent some time searching on google and the only thing I've found is that it wasn't possible 5 months ago. So, is it possible now? And if that's the case, how?
Have you tried searching the documentation?

Zeus guy
Spiny
Spiny
Posts: 26
Joined: Fri Dec 20, 2013 12:46 pm

Re: Need help with lua? - LunaLua General Help

Postby Zeus guy » Wed Apr 06, 2016 2:11 am

PixelPest wrote:
Zeus guy wrote:Ok so it's me again yay.
After some hours of frustration and not getting anything done, I decided to stop coding and start... coding something else. So I remembered something I read on this thread:
Hoeloe wrote:3) When in the reversed section, apply some code using LunaLua's Capture Buffers to flip the screen upside down.
Now I've spent some time searching on google and the only thing I've found is that it wasn't possible 5 months ago. So, is it possible now? And if that's the case, how?
Have you tried searching the documentation?
Yeah, but I didn't find anything.

Kevsoft
Ripper II
Ripper II
Posts: 375
Joined: Sun Jul 27, 2014 8:03 am

Re: Need help with lua? - LunaLua General Help

Postby Kevsoft » Wed Apr 06, 2016 3:45 am

Zeus guy wrote:
PixelPest wrote:
Zeus guy wrote:Ok so it's me again yay.
After some hours of frustration and not getting anything done, I decided to stop coding and start... coding something else. So I remembered something I read on this thread:

Now I've spent some time searching on google and the only thing I've found is that it wasn't possible 5 months ago. So, is it possible now? And if that's the case, how?
Have you tried searching the documentation?
Yeah, but I didn't find anything.
CaputureBuffer API is not in the latest release build. It is only available in the dev-builds.

pal4
Swooper
Swooper
Posts: 63
Joined: Wed Dec 23, 2015 7:57 pm

Re: Need help with lua? - LunaLua General Help

Postby pal4 » Wed Apr 06, 2016 5:27 pm

Quantumenace wrote:You have a LunaSavedVars file almost as new as the lunadll file, which implies that the script is being run and saving that.

Do you happen to have more than one onLoop() function? I think they will overwrite each other if you try to make more than one with the same name.


Edit: General question: What's the difference between API.load and the other API loading functions? API.load isn't mentioned at all on the wiki.
Just one such function. So what you're saying is it should work if I remove the LunaSavedVars file from the folder?

Do lulalua codes only function in an actual game? so far I've only tried it in the editor and the menu screen indicates compatibility with the included lunalua set.

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 » Wed Apr 06, 2016 5:41 pm

pal4 wrote:Do lulalua codes only function in an actual game? so far I've only tried it in the editor and the menu screen indicates compatibility with the included lunalua set.
All Lua codes will work for both the editor and episodes

lotus006
Spike
Spike
Posts: 284
Joined: Thu Sep 24, 2015 12:59 am

Re: Need help with lua? - LunaLua General Help

Postby lotus006 » Wed Apr 06, 2016 5:51 pm

Kevsoft wrote:
Zeus guy wrote:
PixelPest wrote: Have you tried searching the documentation?
Yeah, but I didn't find anything.
CaputureBuffer API is not in the latest release build. It is only available in the dev-builds.
this ?

Code: Select all

   LUAHELPER_DEF_CLASS_SMART_PTR_SHARED(CaptureBuffer, std::shared_ptr)
                    .def(constructor<int, int>())
                    .def("__eq", &LuaProxy::luaUserdataCompare<LuaProxy::Graphics::LuaImageResource>)
                    .def("captureAt", &CaptureBuffer::captureAt),

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 » Wed Apr 06, 2016 6:00 pm

pal4 wrote:
Quantumenace wrote:You have a LunaSavedVars file almost as new as the lunadll file, which implies that the script is being run and saving that.

Do you happen to have more than one onLoop() function? I think they will overwrite each other if you try to make more than one with the same name.


Edit: General question: What's the difference between API.load and the other API loading functions? API.load isn't mentioned at all on the wiki.
Just one such function. So what you're saying is it should work if I remove the LunaSavedVars file from the folder?

Do lulalua codes only function in an actual game? so far I've only tried it in the editor and the menu screen indicates compatibility with the included lunalua set.
No, I didn't say that at all. My point is that something saved that file there, presumably a lunalua script.

You can test if lunadll.lua loads by putting

Text.print()

as the first line. If it loads the script at all it will immediately error out because of incorrect arguments.

The legacy editor should use lunalua scripts. I've never gotten the new editor to test correctly. Is the folder you posted the folder for the level? If so, why are there .lvl files in there?
Last edited by Quantumenace on Wed Apr 06, 2016 8:15 pm, edited 1 time in total.

Nat The Porcupine
Monty Mole
Monty Mole
Posts: 123
Joined: Tue Nov 10, 2015 2:55 pm

Re: Need help with lua? - LunaLua General Help

Postby Nat The Porcupine » Wed Apr 06, 2016 6:34 pm

Does anyone know how to use the onEvent function properly? It doesn't seem to be working for me.

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 » Wed Apr 06, 2016 6:51 pm

Nat The Porcupine wrote:Does anyone know how to use the onEvent function properly? It doesn't seem to be working for me.
You're likely making the mistake of using the argument as a constant, like this:

Code: Select all

function onEvent("Level - Start")
  --Do something
end
This is incorrect and will not work.

Arguments to functions are like local variables. They essentially are variables, that only exist inside that function, so to use onEvent properly, you need to treat the argument as a variable containing the name of the event that just fired, for example:

Code: Select all

function onEvent(eventName)
  if(eventName == "Level - Start") then
    --Do something
  end
end
This is correct and will work. It's also important to know that you cannot have multiple copies of the same event, so you should instead make use of if and elseif statements to account for different events.

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 » Thu Apr 07, 2016 9:02 am

How can I set Birdo's life from 3 to different level? For example if I would want to make Birdo take 5 hits to die instead of 3.

I tried this in lunadll.txt (I took it from this page: http://wohlsoft.ru/pgewiki/LunaDLL_Tutorial)

Code: Select all

#1
AT_SetHits,39,1,9,0,-2,0
#END
That's what the page says about this code:
NPCs in this game don't have health. They have a hit counter. So a mother brain with 9 hits has 1 hit left. A birdo with 1 hit has 2 hits left. A mother brain with -10 hits has 20 hits left. Only NPCs that can normally get hit more than once can have their hit counts manipulated. To find the NPC ID of an NPC, check the graphics folder or a list of NPC IDs. Currently there's no way to specify one single NPC among many that may be in your level. The command runs for every NPC of the type you specify. This goes for all NPC and block commands actually.
What it gives me? Syntax error. Pretty helpful description btw (irony).

And I did try text file with a lot of different numbers, but still Birdo needs 3 hits to die.

Is it just me or Lua is annoying with it's perfect descriptions of errors?

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 » Thu Apr 07, 2016 9:36 am

Mario_and_Luigi_55 wrote: I tried this in lunadll.txt (I took it from this page: http://wohlsoft.ru/pgewiki/LunaDLL_Tutorial)

Code: Select all

#1
AT_SetHits,39,1,9,0,-2,0
#END

This isn't Lua. This is LunaDLL Autocode, which is totally unsupported and highly recommended that you avoid.

Nat The Porcupine
Monty Mole
Monty Mole
Posts: 123
Joined: Tue Nov 10, 2015 2:55 pm

Re: Need help with lua? - LunaLua General Help

Postby Nat The Porcupine » Thu Apr 07, 2016 9:52 am

Hoeloe wrote:
Mario_and_Luigi_55 wrote: I tried this in lunadll.txt (I took it from this page: http://wohlsoft.ru/pgewiki/LunaDLL_Tutorial)

Code: Select all

#1
AT_SetHits,39,1,9,0,-2,0
#END

This isn't Lua. This is LunaDLL Autocode, which is totally unsupported and highly recommended that you avoid.
I agree with HoeLoe. Stay away from autocode. However, seeing as you probably lack the necessary knowledge to recode this in lua from scratch, I would recommend checking out the How To: Autocode to LunaLua tutorial on the PGE wiki. That should help you convert most autocode into useable LunaLua, but I can't exactly guarantee you that it will always work.

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 Apr 07, 2016 8:22 pm

Hey, how come my episode names won't show up in play mode? :?: :?

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 » Thu Apr 07, 2016 8:46 pm

Circle Guy wrote:Hey, how come my episode names won't show up in play mode? :?: :?
How is this a LunaLua issue? Unless you have code to show the episode's names during gameplay they won't. If you've tried, seeing the code you have would really help

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 Apr 07, 2016 10:25 pm

PixelPest wrote:
Circle Guy wrote:Hey, how come my episode names won't show up in play mode? :?: :?
How is this a LunaLua issue? Unless you have code to show the episode's names during gameplay they won't. If you've tried, seeing the code you have would really help
It's a lua issue because I'm using the Lua version and it only has this issue.

HenryRichard
Reznor
Reznor
Posts: 2843
Joined: Mon Dec 23, 2013 12:09 pm
Flair: Is this where I type my password?
Contact:

Re: Need help with lua? - LunaLua General Help

Postby HenryRichard » Thu Apr 07, 2016 10:29 pm

Did you set the .wld file's name in the editor?

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 » Fri Apr 08, 2016 6:21 am

HenryRichard wrote:Did you set the .wld file's name in the editor?
Yeah, but I mean NO world names are showing up. Even the Invasion 2!

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 » Fri Apr 08, 2016 6:52 am

Circle Guy wrote:
HenryRichard wrote:Did you set the .wld file's name in the editor?
Yeah, but I mean NO world names are showing up. Even the Invasion 2!
Oh. You mean on the main screen. I don't think you could really fix that easily. Have you actually checked to see if the .wld files have names inside the file?


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari