Page 1 of 1

where can i learn?

Posted: Tue Aug 11, 2020 12:56 am
by lolcode
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

Re: where can i learn?

Posted: Tue Aug 11, 2020 1:35 am
by Emral
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.

Re: where can i learn?

Posted: Tue Aug 11, 2020 2:22 am
by lolcode
saw this lil' code

Image

is it posible to have more than 1 variable?

Re: where can i learn?

Posted: Tue Aug 11, 2020 4:03 am
by Emral
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.

Re: where can i learn?

Posted: Tue Aug 11, 2020 4:51 am
by lolcode
is OnNPCHarm function able to change variables?

Re: where can i learn?

Posted: Tue Aug 11, 2020 5:09 am
by Emral
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?

Re: where can i learn?

Posted: Tue Aug 11, 2020 5:13 am
by lolcode
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?

Re: where can i learn?

Posted: Tue Aug 11, 2020 5:22 am
by Emral
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.

Re: where can i learn?

Posted: Tue Aug 11, 2020 5:28 am
by lolcode
but...
will it affect the variable itself?

Re: where can i learn?

Posted: Tue Aug 11, 2020 5:34 am
by Emral
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.

Re: where can i learn?

Posted: Tue Aug 11, 2020 6:47 am
by lolcode
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

Re: where can i learn?

Posted: Tue Aug 11, 2020 7:17 am
by Emral
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.

Re: where can i learn?

Posted: Tue Aug 11, 2020 7:42 am
by lolcode
third is still confusing

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

Re: where can i learn?

Posted: Tue Aug 11, 2020 7:51 am
by Emral
Cancels all NPC deaths:

Code: Select all

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

Re: where can i learn?

Posted: Tue Aug 11, 2020 7:56 am
by lolcode
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

Re: where can i learn?

Posted: Tue Aug 11, 2020 8:23 am
by Emral
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

Re: where can i learn?

Posted: Tue Aug 11, 2020 3:55 pm
by Cedur
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

Re: where can i learn?

Posted: Tue Aug 11, 2020 4:42 pm
by Emral
ok

Re: where can i learn?

Posted: Thu Aug 05, 2021 9:02 pm
by lolcode
i learned