where can i learn?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

where can i learn?

Postby lolcode » Tue Aug 11, 2020 12:56 am

hi guys
i need to know the quickest and easiest way to learn lunalua

Added in 3 minutes 6 seconds:
in text form and not outdated if possible

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

Re: where can i learn?

Postby Emral » Tue Aug 11, 2020 1:35 am

https://www.lua.org/pil/contents.html#P1
https://wohlsoft.ru/pgewiki/How_To:_LunaLua_basics
Some places to start.
If you encounter anything deprecated on the wiki it doesn't matter as older code is still supported. The tutorials and docs on this page are generally a good place to start.
Additionally you can read all the smbx2 basegame code for additional examples of things, though some of the files may be more difficult to comprehend than others.

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: where can i learn?

Postby lolcode » Tue Aug 11, 2020 2:22 am

saw this lil' code

Image

is it posible to have more than 1 variable?

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

Re: where can i learn?

Postby Emral » Tue Aug 11, 2020 4:03 am

the lolie wrote:
Tue Aug 11, 2020 2:22 am
saw this lil' code

Image

is it posible to have more than 1 variable?
Try it! The examples are for you to follow along. Learning always goes faster if you try things out yourself.
Or you could also read further into the tutorial to the point where a second variable is introduced. I recommend actually writing code while working through tutorials either way.

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: where can i learn?

Postby lolcode » Tue Aug 11, 2020 4:51 am

is OnNPCHarm function able to change variables?

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

Re: where can i learn?

Postby Emral » Tue Aug 11, 2020 5:09 am

Not quite sure what you mean. Do you have an example piece of code you wrote which you can use to describe what you're trying to do?

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: where can i learn?

Postby lolcode » Tue Aug 11, 2020 5:13 am

not yet

Added in 2 minutes 45 seconds:
i mean if i name variable bosshp
and type this:

function OnNPCHarm()
bosshp = bosshp - 1
end

will it work?

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

Re: where can i learn?

Postby Emral » Tue Aug 11, 2020 5:22 am

No, because of a capitalization error:
It's onNPCHarm, not OnNPCHarm.

Running that code will reveal that the variable decrements whenever any NPC dies for any reason, assuming bosshp is a number. Go try it in your luna.lua!
If you need to debug your code:
You can put Misc.dialog(myVariable) into any line to get a popup notification of whatever you replace myVariable with.
You can also put Text.print(text, x, y) into onTick or onDraw to print something without interrupting gameplay. x and y should be numbers that represent on-screen coordinates (for example you can try Text.print("Hi", 100, 100) or Text.print(bosshp, 100, 100).

As a general rule, variables exist within any scope smaller than their own. If you indent your code properly, that means that a variable exists and can be edited anywhere below its definition until the code become less indented the next time.

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: where can i learn?

Postby lolcode » Tue Aug 11, 2020 5:28 am

but...
will it affect the variable itself?

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

Re: where can i learn?

Postby Emral » Tue Aug 11, 2020 5:34 am

the lolie wrote:
Tue Aug 11, 2020 5:28 am
but...
will it affect the variable itself?
I just said. Yes if you fix the capitalization error. Try it. Try the code you conceptualize. Use the debug functions I just described to visualize what happens.

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: where can i learn?

Postby lolcode » Tue Aug 11, 2020 6:47 am

now i need to know 3 things:
how to do rng
how to delay code by certain period of time
how to make npc execute onNPCHarm but not die

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

Re: where can i learn?

Postby Emral » Tue Aug 11, 2020 7:17 am

The first can be done using the RNG library automatically loaded in beta 4.
https://wohlsoft.ru/pgewiki/Rng.lua
Documentation is still the same, but you don't have to load the library and can do things like RNG.random(0,1) immediately.

The second can be done using a timer variable, described in the tutorial you previously read.

The third can be found in the documentation to onNPCKill/onNPCHarm's parameters.
https://wohlsoft.ru/pgewiki/LunaLua_events
In particular, take a look at the page for the "Event" eventObj parameter to onNPCKill. onNPCHarm gets it, too.

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: where can i learn?

Postby lolcode » Tue Aug 11, 2020 7:42 am

third is still confusing

Added in 4 minutes 58 seconds:
can i have an example on how to use it

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

Re: where can i learn?

Postby Emral » Tue Aug 11, 2020 7:51 am

Cancels all NPC deaths:

Code: Select all

function onNPCHarm(killEvent, killedNPC, killReason)
    killEvent.cancelled = true
end

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: where can i learn?

Postby lolcode » Tue Aug 11, 2020 7:56 am

so...
if i need to cancell death npc 752...
i need to add killedNPC = 752
right?

Added in 19 minutes 19 seconds:
oh and also do these codes work in npcs file

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

Re: where can i learn?

Postby Emral » Tue Aug 11, 2020 8:23 am

Try things, and consult online documentation or post error messages if you run into dead ends. I'll stop responding to hypotheticals from here on out that can be easily tested.

As for the "npcs file", yes. It's a bit different, though, which you will need knowledge on the npc-n template and this tutorial for, though: https://wohlsoft.ru/pgewiki/How_To:_Mak ... ua_library

Cedur
Link
Link
Posts: 7073
Joined: Tue Jun 28, 2016 10:14 am
Flair: I'm gone, for chess and minesweeper
Pronouns: he/him

Re: where can i learn?

Postby Cedur » Tue Aug 11, 2020 3:55 pm

Honestly my problem with lua is not the language itself (being a mathematician I do have the intellect to deal with languages) but lacking documentation of how it interferes with the game and how all the stuff is referenced / called etc

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

Re: where can i learn?

Postby Emral » Tue Aug 11, 2020 4:42 pm

ok

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: where can i learn?

Postby lolcode » Thu Aug 05, 2021 9:02 pm

i learned


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 4 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari