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?
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Tue Jan 09, 2018 5:48 pm
PixelPest wrote:Notxarb wrote:I have multiple questions.
1. Is there any way to detect if a number is an integer?
2. I made a time limit-- how do I make it kill Mario when it reaches zero?
3. I was having trouble positioning printed text. Are its coordinates measured in pixels?
4. What are the dimensions of one printed character (in pixels or otherwise?)
5. Is there a way to make a loop stop? (e.g. exit loop)
6. Can you make a function loop every "x" ticks?
7. Can you create new npcs (adding more IDs) or other graphics?
1. Lua does not differentiate between integer, float, and other number types. Why specifically do you need to test this? There might be a better way.
2. Are you using an API to do so? (leveltimer.lua, etc.) If so, this is usually default. If you're using your own call player:kill();
3. Measured in pixels and using screen coordinates; top left is (0, 0), bottom right is (800, 600).
4. Depends on the character and its frame. You can use player.width and player.height to find these values.
5. Use a while loop or type break; on its own line inside a loop to break it.
6. You can call a function after a decreasing variable hits zero (and then reset that variable). Could probably use the eventu library but I wouldn't for this.
7. You can create new NPCs up to ID 300 in Beta3. In Beta4, we've added IDs up to 1000 iirc, a limit which can be extended easily, to add more NPCs. You can also replace current NPC graphics if you just need an existing AI. NPCs aren't easy to program
1: I just thought it might be useful. And I did find a better way to do what I was trying.
2: What do you mean by API? I just made my own timer. Is this like a pre-made one?
3: Ah. Thanks.
4: Well, I meant character as in a letter or number. They all seem to be around 16 pixels wide-- is this true?
5: Ok.
6: Ok.
7: Do you just have to create new NPCs and put them in the level folder/ game folder and you'll be able to use them?
The reason I asked a few of these is because I wanted to have a global tick count and make the timer decrease every 20 ticks. But the only way I could do this by basing it off the timer would be to divide the tick count by 20 and check if it is an integer.
Alternatively, I have a way to check for integers regardless:
Input number n.
Set c to zero.
Have c count up by one until it is greater than or equal to n.
If it is equal to n, n is an integer.
If it is greater than n, n is not an integer.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9887
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Tue Jan 09, 2018 6:35 pm
Notxarb wrote:2: What do you mean by API? I just made my own timer. Is this like a pre-made one?
He means "library", which are scripts you can load using "local myLib = API.load("myLib") where myAPI is to be replaced with the library's name.
Notxarb wrote:4: Well, I meant character as in a letter or number. They all seem to be around 16 pixels wide-- is this true?
16 pixels wide and 2 for spaces in between, yup.
Notxarb wrote:7: Do you just have to create new NPCs and put them in the level folder/ game folder and you'll be able to use them?
You can basically make a Beta 3 npc do nothing by creating a folder as a subfolder of your level folder, called "NPCs", and putting a library in there which has the same name as the one you want to replace. Then just put the line "return {}" in there, and you got yourself an empty NPC slot. Then you can replace that slot with a NPC you have created.
Notxarb wrote:But the only way I could do this by basing it off the timer would be to divide the tick count by 20 and check if it is an integer.
Couldn't you just use math.floor or math.ceil to round to an integer for drawing, but keep it a float internally?
|
|
|
|
|
|
|
|
|
-
The0x539
- Eerie

- Posts: 751
- Joined: Fri Jan 22, 2016 8:02 pm
Postby The0x539 » Tue Jan 09, 2018 6:36 pm
Notxarb wrote:
The reason I asked a few of these is because I wanted to have a global tick count and make the timer decrease every 20 ticks. But the only way I could do this by basing it off the timer would be to divide the tick count by 20 and check if it is an integer.
Alternatively, I have a way to check for integers regardless:
Input number n.
Set c to zero.
Have c count up by one until it is greater than or equal to n.
If it is equal to n, n is an integer.
If it is greater than n, n is not an integer.
Code: Select all local lunatime = API.load("core/lunatime")
function onTick()
if lunatime.tick() % 20 == 0 then
--do stuff
end
end
please avoid doing either of the things you just came up with
Modulo is a very useful mathematical operator. Division is fairly expensive, and that integer test is most likely extremely inefficient compared to checking whether a%1==0 (not to mention that that check isn't necessary when division itself isn't).
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Tue Jan 09, 2018 7:26 pm
Enjl wrote:Notxarb wrote:7: Do you just have to create new NPCs and put them in the level folder/ game folder and you'll be able to use them?
You can basically make a Beta 3 npc do nothing by creating a folder as a subfolder of your level folder, called "NPCs", and putting a library in there which has the same name as the one you want to replace. Then just put the line "return {}" in there, and you got yourself an empty NPC slot. Then you can replace that slot with a NPC you have created.
That seems fairly complicated, and I just started LunaLua yesterday or so. Maybe in a while I'll come back to this...
Enjl wrote:Notxarb wrote:But the only way I could do this by basing it off the timer would be to divide the tick count by 20 and check if it is an integer.
Couldn't you just use math.floor or math.ceil to round to an integer for drawing, but keep it a float internally?
I guess you're right. I actually did come up with something like that, but it was after I figured out the right way to do it.
Is it possible to force Mario to enter ANY state, such as his statue form? I might deprive the tanooki suit of its flight power and redesign it as a metal cap from Super Mario 64. If I can't do this, I might also just make a separate powerup entirely that changes Mario's properties.
Also, how can I use "loop while"? I tried it but I couldn't figure out how to format it properly.
One more thing: Is Player.speedX outdated? I tried to use it and it said it didn't exist.
The0x539 wrote:Notxarb wrote:
The reason I asked a few of these is because I wanted to have a global tick count and make the timer decrease every 20 ticks. But the only way I could do this by basing it off the timer would be to divide the tick count by 20 and check if it is an integer.
Alternatively, I have a way to check for integers regardless:
Input number n.
Set c to zero.
Have c count up by one until it is greater than or equal to n.
If it is equal to n, n is an integer.
If it is greater than n, n is not an integer.
Code: Select all local lunatime = API.load("core/lunatime")
function onTick()
if lunatime.tick() % 20 == 0 then
--do stuff
end
end
please avoid doing either of the things you just came up with
Modulo is a very useful mathematical operator. Division is fairly expensive, and that integer test is most likely extremely inefficient compared to checking whether a%1==0 (not to mention that that check isn't necessary when division itself isn't).
I didn't understand some of that, and I don't need to yet, but I did just start LunaLua like yesterday so I haven't explored it much so far.
Last edited by Novarender on Tue Jan 09, 2018 8:16 pm, edited 1 time in total.
|
|
|
|
|
|
|
|
|
-
The0x539
- Eerie

- Posts: 751
- Joined: Fri Jan 22, 2016 8:02 pm
Postby The0x539 » Tue Jan 09, 2018 8:05 pm
Notxarb wrote:
The0x539 wrote:Notxarb wrote:
The reason I asked a few of these is because I wanted to have a global tick count and make the timer decrease every 20 ticks. But the only way I could do this by basing it off the timer would be to divide the tick count by 20 and check if it is an integer.
Alternatively, I have a way to check for integers regardless:
Input number n.
Set c to zero.
Have c count up by one until it is greater than or equal to n.
If it is equal to n, n is an integer.
If it is greater than n, n is not an integer.
Code: Select all local lunatime = API.load("core/lunatime")
function onTick()
if lunatime.tick() % 20 == 0 then
--do stuff
end
end
please avoid doing either of the things you just came up with
Modulo is a very useful mathematical operator. Division is fairly expensive, and that integer test is most likely extremely inefficient compared to checking whether a%1==0 (not to mention that that check isn't necessary when division itself isn't).
I didn't understand some of that, and I don't need to yet, but I did just start LunaLua like yesterday so I haven't explored it much so far.
lunatime is an API that keeps track of how many ticks and seconds have passed since the level has started, as well as providing functions for converting between the two.
% is the modulo operator in Lua.
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Tue Jan 09, 2018 8:30 pm
The0x539 wrote:lunatime is an API that keeps track of how many ticks and seconds have passed since the level has started, as well as providing functions for converting between the two.
% is the modulo operator in Lua.
Oh. Thanks!
Do you know how many ticks are in a second in Lua?
EDIT: Nvm
Last edited by Novarender on Tue Jan 09, 2018 8:40 pm, edited 1 time in total.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9887
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Tue Jan 09, 2018 8:32 pm
Notxarb wrote:The0x539 wrote:lunatime is an API that keeps track of how many ticks and seconds have passed since the level has started, as well as providing functions for converting between the two.
% is the modulo operator in Lua.
Oh. Thanks!
Do you know how many ticks are in a second in Lua?
Approximately 64. 2500/39, to be exact.
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Tue Jan 09, 2018 9:09 pm
I was trying to use things like Player.speedX and Player.powerup as values, but it didn't work. The site says it is a "field" type of command. What's a field and how do I use it?
|
|
|
|
|
|
|
|
|
-
Quantumenace
- Chain Chomp

- Posts: 308
- Joined: Mon Dec 28, 2015 2:17 am
Postby Quantumenace » Tue Jan 09, 2018 9:14 pm
Is it possible to force Mario to enter ANY state, such as his statue form? I might deprive the tanooki suit of its flight power and redesign it as a metal cap from Super Mario 64. If I can't do this, I might also just make a separate powerup entirely that changes Mario's properties.
Try looking at the player memory offsets 0x4A, 0x4C and 0x4E, which have to do with the statue form. I haven't experimented much with this. I'd think Mario can't move with it enabled though.
Also, how can I use "loop while"? I tried it but I couldn't figure out how to format it properly.
"while" is itself a loop command.
One more thing: Is Player.speedX outdated? I tried to use it and it said it didn't exist.
"Player" (capitalized) is the name of the table of player-related functions. The name for player 1 is "player". "player.speedX" will work.
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Tue Jan 09, 2018 9:22 pm
Quantumenace wrote:Is it possible to force Mario to enter ANY state, such as his statue form? I might deprive the tanooki suit of its flight power and redesign it as a metal cap from Super Mario 64. If I can't do this, I might also just make a separate powerup entirely that changes Mario's properties.
Try looking at the player memory offsets 0x4A, 0x4C and 0x4E, which have to do with the statue form. I haven't experimented much with this. I'd think Mario can't move with it enabled though.
Ok. It doesn't matter if he can move. I have plans.
Quantumenace wrote:One more thing: Is Player.speedX outdated? I tried to use it and it said it didn't exist.
"Player" (capitalized) is the name of the table of player-related functions. The name for player 1 is "player". "player.speedX" will work.
Yes, I just realised this before I saw your comment. I don't know why the site kept capitalizing Player.
|
|
|
|
|
|
|
|
|
-
PixelPest
- Link

- Posts: 7111
- Joined: Sun Jul 12, 2015 5:38 pm
- Flair: Tamer of Boom Booms
-
Contact:
Postby PixelPest » Tue Jan 09, 2018 10:46 pm
It capitalizes "Player" to indicate that that property belongs to all objects of the Player class, such as the "player" object. Anything that isn't a constructor or a static function in a class is inherited by the class objects on instantiation (creation). This includes methods like "kill" and fields like "speedX". The constructors and static functions are called by the class itself and not as part of a specific object so when using a function like "get" within the Player class, you will call it with a capital "P" ("Player.get")
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Wed Jan 10, 2018 6:28 am
Enjl wrote:Notxarb wrote:The0x539 wrote:lunatime is an API that keeps track of how many ticks and seconds have passed since the level has started, as well as providing functions for converting between the two.
% is the modulo operator in Lua.
Oh. Thanks!
Do you know how many ticks are in a second in Lua?
Approximately 64. 2500/39, to be exact.
First, lunatime, being a core API, doesn't need to be explicitly loaded. You can just use it.
Secondly, lunatime has a function called lunatime.toSeconds (as well as lunatime.toTicks) used for converting values between seconds and ticks so that you don't have to use obtuse calculations like 2500/39 and can use the more readable lunatime.toTicks(1).
I also wouldn't worry about a single modulo use. The0x539 is right that modulus is a fairly expensive operator compared to something like addition, but it's not going to lag up your game any time soon.
|
|
|
|
|
|
|
|
|
-
Taycamgame
- Gold Yoshi Egg

- Posts: 1483
- Joined: Mon Jun 19, 2017 11:35 am
- Flair: Stargard
-
Contact:
Postby Taycamgame » Wed Jan 10, 2018 11:41 am
What is the meaning of 2500/39, and why isn't that something else like 2000/40?
|
|
|
|
|
|
|
|
|
-
The0x539
- Eerie

- Posts: 751
- Joined: Fri Jan 22, 2016 8:02 pm
Postby The0x539 » Wed Jan 10, 2018 12:03 pm
Taycamgame wrote:What is the meaning of 2500/39, and why isn't that something else like 2000/40?
A tick lasts 15.6 milliseconds (this probably wasn't intended but it's the way things are). With this length, "39 ticks pass in 2500 milliseconds" is the smallest integer expression of the ratio between ticks and milliseconds.
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Wed Jan 10, 2018 4:42 pm
How do I use and format "while"? Can you give an example?
What about math.flor and math.ceil?
Also, what is the default jump height?
|
|
|
|
|
|
|
|
|
-
The0x539
- Eerie

- Posts: 751
- Joined: Fri Jan 22, 2016 8:02 pm
Postby The0x539 » Wed Jan 10, 2018 6:48 pm
Notxarb wrote:How do I use and format "while"? Can you give an example?
What about math.flor and math.ceil?
Also, what is the default jump height?
Code: Select all while someCondition do
--do stuff
end
repeat
--do stuff
until someCondition
floor and ceil round up and down to the nearest integer.
The default jump "height" is 20 ticks.
|
|
|
|
|
|
|
|
|
-
Quantumenace
- Chain Chomp

- Posts: 308
- Joined: Mon Dec 28, 2015 2:17 am
Postby Quantumenace » Wed Jan 10, 2018 6:50 pm
while (condition) do
...
end
example:
x = math.floor(num)
-rounds down to nearest integer
x = math.ceil(num)
-rounds up to nearest integer
The jump height isn't a fixed number, it depends on the character, gravity, a certain jump momentum timer IIRC and how fast the character is running.
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Wed Jan 10, 2018 10:58 pm
Can you tell me what's wrong here?
This is script for a triple jump sequence (TJS):
Code: Select all --double jump
function onJumpEnd() --after landing on ground from jump
while loop < 64 do --for 1 second
if player.speedX > 4 or player.speedX < -4 then --if fast enough
Defines.jumpheight = 100 --can jump higher (double jump) [set to high number for testing]
else --if too slow
Defines.jumpheight = 20 --jump normally
end
loop = loop + 1 --adding to timer
end
loop = 0 --reset timer
Defines.jumpheight = 20 --jump normally after 1 second
end
For some reason, it worked once but in a glitchy way, and since then I probably modified it, but I still don't know why it's not working. Nothing is failing except the fact that he doesn't do a double jump (in a TJS).
|
|
|
|
|
|
|
|
|
-
Quantumenace
- Chain Chomp

- Posts: 308
- Joined: Mon Dec 28, 2015 2:17 am
Postby Quantumenace » Thu Jan 11, 2018 2:49 am
It's important to note that a loop doesn't wait for the next tick. That won't take place over a second, it will just run that code 64 times in a row right when you land.
What you'll want to do is have a timer variable that is set to 64 when you land. Then, on onTick() you'll want to check if it isn't zero, decrease the timer by 1, and do the code for the jump. You don't need a loop for that.
|
|
|
|
|
|
|
|
|
-
Novarender
- Tweeter

- Posts: 145
- Joined: Sat Aug 06, 2016 6:59 pm
- Flair: Whoa
Postby Novarender » Thu Jan 11, 2018 5:13 pm
Quantumenace wrote:What you'll want to do is have a timer variable that is set to 64 when you land. Then, on onTick() you'll want to check if it isn't zero, decrease the timer by 1, and do the code for the jump. You don't need a loop for that.
How exactly could I do this? It needs to be within "onJumpEnd", and it never works when I try to use "function onTick()" in something else. It just freezes.
Is there a different way I can use onTick()?
|
|
|
|
|
Return to “LunaLua”
Users browsing this forum: No registered users and 0 guests
|