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?
|
|
|
|
-
Mario_and_Luigi_55
- Spike

- Posts: 270
- Joined: Sat Feb 27, 2016 12:01 pm
Postby Mario_and_Luigi_55 » Sat Apr 23, 2016 5:36 am
RhysOwens wrote:Hoeloe wrote:RhysOwens wrote:
I was copying the functions in the lua file near the beginning.
But you didn't understand enough of what you were doing to know that you need to define variables before you use them.
Do I call the variable HealthPoint?
I've abandoned the HealthPoint thing for now.
Yes. You can call it whatever you want for example:
Code: Select all local something = API.load "HealthPoint"
But then you don't use Code: Select all HealthPoint.setNPCHealth(npcID, Health)
, but Code: Select all something.setNPCHealth(npcID, Health)
Also, I want to improve the ? mushroom (npc-273). I want to make it give player completely random NPC to the powerup box, after he grabs it. How can I do that? I'll need to use math.random or rng.lua (that's what I know, but here my knowledge ends)
|
|
|
|
|
|
|
|
|
-
PixelPest
- Link

- Posts: 7111
- Joined: Sun Jul 12, 2015 5:38 pm
- Flair: Tamer of Boom Booms
-
Contact:
Postby PixelPest » Sat Apr 23, 2016 7:57 am
Mario_and_Luigi_55 wrote:Also, I want to improve the ? mushroom (npc-273). I want to make it give player completely random NPC to the powerup box, after he grabs it. How can I do that? I'll need to use math.random or rng.lua (that's what I know, but here my knowledge ends)
I would recommend using rng.lua for sure. Also, do you mean after the player eats npc-263? That's the ?-mushroom. If so, you would start by loading rng.lua. Next, start with the onNPCKill() event and inside test to see if npc-263 has been killed. Then, if npc-263 was killed use the parameter player.reservePowerup and make that equal a random number (using rng)
|
|
|
|
|
|
|
|
|
-
Mario_and_Luigi_55
- Spike

- Posts: 270
- Joined: Sat Feb 27, 2016 12:01 pm
Postby Mario_and_Luigi_55 » Sat Apr 23, 2016 8:58 am
PixelPest wrote:Mario_and_Luigi_55 wrote:Also, I want to improve the ? mushroom (npc-273). I want to make it give player completely random NPC to the powerup box, after he grabs it. How can I do that? I'll need to use math.random or rng.lua (that's what I know, but here my knowledge ends)
I would recommend using rng.lua for sure. Also, do you mean after the player eats npc-263? That's the ?-mushroom. If so, you would start by loading rng.lua. Next, start with the onNPCKill() event and inside test to see if npc-263 has been killed. Then, if npc-263 was killed use the parameter player.reservePowerup and make that equal a random number (using rng)
This code works, but it's the shortest longest code in the world Can I somehow make it shorter?
|
|
|
|
|
|
|
|
|
-
PixelPest
- Link

- Posts: 7111
- Joined: Sun Jul 12, 2015 5:38 pm
- Flair: Tamer of Boom Booms
-
Contact:
Postby PixelPest » Sat Apr 23, 2016 9:10 am
Mario_and_Luigi_55 wrote:PixelPest wrote:Mario_and_Luigi_55 wrote:Also, I want to improve the ? mushroom (npc-273). I want to make it give player completely random NPC to the powerup box, after he grabs it. How can I do that? I'll need to use math.random or rng.lua (that's what I know, but here my knowledge ends)
I would recommend using rng.lua for sure. Also, do you mean after the player eats npc-263? That's the ?-mushroom. If so, you would start by loading rng.lua. Next, start with the onNPCKill() event and inside test to see if npc-263 has been killed. Then, if npc-263 was killed use the parameter player.reservePowerup and make that equal a random number (using rng)
This code works, but it's the shortest longest code in the world Can I somehow make it shorter?
Make a table with all of those numbers and replace all of that stuff with the name of the table, like: switchTable = {numbers here}
|
|
|
|
|
|
|
|
|
-
RhysOwens
- Nipper

- Posts: 423
- Joined: Fri Apr 22, 2016 2:53 am
Postby RhysOwens » Sat Apr 23, 2016 9:41 am
Mario_and_Luigi_55 wrote:
Yes. You can call it whatever you want for example:
Code: Select all local something = API.load "HealthPoint"
But then you don't use Code: Select all HealthPoint.setNPCHealth(npcID, Health)
, but Code: Select all something.setNPCHealth(npcID, Health)
Also, I want to improve the ? mushroom (npc-273). I want to make it give player completely random NPC to the powerup box, after he grabs it. How can I do that? I'll need to use math.random or rng.lua (that's what I know, but here my knowledge ends)
I've done what you've done and this is my new code:
Code: Select all Health = 0
local Health = API.load "HealthPoint"
function Health.setNPCHealth(54, 5)
end
And the error I'm now getting says: <name> or '...' expected near '54'
From 54 I mean NPC 54 if that helps.
|
|
|
|
|
|
|
|
|
-
PixelPest
- Link

- Posts: 7111
- Joined: Sun Jul 12, 2015 5:38 pm
- Flair: Tamer of Boom Booms
-
Contact:
Postby PixelPest » Sat Apr 23, 2016 9:47 am
RhysOwens wrote:Mario_and_Luigi_55 wrote:
Yes. You can call it whatever you want for example:
Code: Select all local something = API.load "HealthPoint"
But then you don't use Code: Select all HealthPoint.setNPCHealth(npcID, Health)
, but Code: Select all something.setNPCHealth(npcID, Health)
Also, I want to improve the ? mushroom (npc-273). I want to make it give player completely random NPC to the powerup box, after he grabs it. How can I do that? I'll need to use math.random or rng.lua (that's what I know, but here my knowledge ends)
I've done what you've done and this is my new code:
Code: Select all Health = 0
local Health = API.load "HealthPoint"
function Health.setNPCHealth(54, 5)
end
And the error I'm now getting says: <name> or '...' expected near '54'
From 54 I mean NPC 54 if that helps.
No no no. Use function onTick() and then set the variable inside that event
|
|
|
|
|
|
|
|
|
-
S1eth
- Bot

- Posts: 54
- Joined: Sat Apr 23, 2016 10:44 am
Postby S1eth » Sat Apr 23, 2016 10:48 am
RhysOwens wrote:Mario_and_Luigi_55 wrote:
Yes. You can call it whatever you want for example:
Code: Select all local something = API.load "HealthPoint"
But then you don't use Code: Select all HealthPoint.setNPCHealth(npcID, Health)
, but Code: Select all something.setNPCHealth(npcID, Health)
Also, I want to improve the ? mushroom (npc-273). I want to make it give player completely random NPC to the powerup box, after he grabs it. How can I do that? I'll need to use math.random or rng.lua (that's what I know, but here my knowledge ends)
I've done what you've done and this is my new code:
Code: Select all Health = 0
local Health = API.load "HealthPoint"
function Health.setNPCHealth(54, 5)
end
And the error I'm now getting says: <name> or '...' expected near '54'
From 54 I mean NPC 54 if that helps.
This will answer all your questions:
http://www.lua.org/pil/contents.html
And after you've read all that, if you need help with SMBX specifically, watch: https://www.youtube.com/watch?v=E69ti1Q ... wd5hW2KwOw
and http://wohlsoft.ru/pgewiki/How_To:_Make ... custom_API
|
|
|
|
|
|
|
|
|
-
underFlo
- Wart

- Posts: 4456
- Joined: Mon Jul 14, 2014 10:44 am
- Flair: sup im lesbiab
- Pronouns: They/She
-
Contact:
Postby underFlo » Sat Apr 23, 2016 12:46 pm
That 2nd code doesn't work because using or like this only works with booleans.
For the 1st code, you're only decreasing TablePosition once every frame, so it won't check for all the table positions. What you should do is add a loop, like this: http://www.hastebin.com/ijinenebam.lua
|
|
|
|
|
|
|
|
|
-
S1eth
- Bot

- Posts: 54
- Joined: Sat Apr 23, 2016 10:44 am
Postby S1eth » Sat Apr 23, 2016 12:48 pm
You need to iterate over the table and check for every index if the table value equals the new powerup value.
Here, I made a "contains" function, which does that for you. It checks if a given table contains a given value, and returns true if it does, and false if it doesn't.
http://www.hastebin.com/teviyaxumo.lua
BTW, you misspelled TableLength. But you don't need that. There is #tableName or table.getn(tableName) for that.
|
|
|
|
|
|
|
|
|
-
Mario_and_Luigi_55
- Spike

- Posts: 270
- Joined: Sat Feb 27, 2016 12:01 pm
Postby Mario_and_Luigi_55 » Sat Apr 23, 2016 1:07 pm
Thank you! I wouldn't probably guess how to do that and I would go back to old code.
|
|
|
|
|
|
|
|
|
-
pal4
- Swooper

- Posts: 63
- Joined: Wed Dec 23, 2015 7:57 pm
Postby pal4 » Sat Apr 23, 2016 6:19 pm
Enjl wrote:It's so your code is actually formatted well. You can also use the Code: Select all bbcode but that's limited to like 6 lines at a time. Just pasting it to the page makes it unreadable.[/quote]
What is the [code] bbcode,? Also you didn't tell me how I'm supposed to actually use hastebin.
|
|
|
|
|
|
|
|
|
-
PixelPest
- Link

- Posts: 7111
- Joined: Sun Jul 12, 2015 5:38 pm
- Flair: Tamer of Boom Booms
-
Contact:
Postby PixelPest » Sat Apr 23, 2016 6:21 pm
pal4 wrote:Enjl wrote:It's so your code is actually formatted well. You can also use the Code: Select all bbcode but that's limited to like 6 lines at a time. Just pasting it to the page makes it unreadable.[/quote]
What is the [code] bbcode,? Also you didn't tell me how I'm supposed to actually use hastebin.[/quote]
It's not that hard. You just press paste. Then you press save. Then you copy the url and paste it here
|
|
|
|
|
|
|
|
|
-
Quantumenace
- Chain Chomp

- Posts: 308
- Joined: Mon Dec 28, 2015 2:17 am
Postby Quantumenace » Sat Apr 23, 2016 7:24 pm
Is there a way to convert an NPC pointer variable into something I can use in NPC:mem() ?
I want to try to put a pointer to an NPC in 0x140, because otherwise an NPC i'm using in a simulated warp-type generator assumes its generator is to its right and immediately thinks it's "finished" if it's moving left.
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Sat Apr 23, 2016 7:41 pm
Quantumenace wrote:Is there a way to convert an NPC pointer variable into something I can use in NPC:mem() ?
I want to try to put a pointer to an NPC in 0x140, because otherwise an NPC i'm using in a simulated warp-type generator assumes its generator is to its right and immediately thinks it's "finished" if it's moving left.
If you just want to store references attached to the NPC, the best way is to wrap it with pnpc and using the PNPC.data table that is attached to all pnpc objects.
|
|
|
|
|
|
|
|
|
-
Quantumenace
- Chain Chomp

- Posts: 308
- Joined: Mon Dec 28, 2015 2:17 am
Postby Quantumenace » Sat Apr 23, 2016 8:01 pm
Hoeloe wrote:Quantumenace wrote:Is there a way to convert an NPC pointer variable into something I can use in NPC:mem() ?
I want to try to put a pointer to an NPC in 0x140, because otherwise an NPC i'm using in a simulated warp-type generator assumes its generator is to its right and immediately thinks it's "finished" if it's moving left.
If you just want to store references attached to the NPC, the best way is to wrap it with pnpc and using the PNPC.data table that is attached to all pnpc objects.
Yes, I do that for other stuff but it won't work for what I want here because it's part of the SMBX programming. I can make an NPC act like it's being spawned from a warp-type generator by setting its 0x138 to 4 and its 0x144 to the generator direction. 0x140 holds a value that is set for NPCs spawned by a generator so I think it's some kind of reference.
If it's moving right or down, it keeps moving until I set those to something else and stop it. But if it's going up or left, it "drops out" immediately. I can force it to keep going by setting those every tick but it appears in front of blocks instead of behind.
...But I found that setting those values again at onTickEnd fixes the priority. So maybe I don't need to bother, but I'd still like to know if it's possible.
|
|
|
|
|
|
|
|
|
-
RhysOwens
- Nipper

- Posts: 423
- Joined: Fri Apr 22, 2016 2:53 am
Postby RhysOwens » Sun Apr 24, 2016 6:32 am
Finally the Fighterfly has more health.
This was my final code:
Code: Select all local Health = 0
local Health = API.load "HealthPoint";
function onStart()
Health.setNPCHealth(54, 12)
end
But it seems that all NPC take more hits and some still give you points when their not dead,
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Phanto

- Posts: 1465
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Sun Apr 24, 2016 7:08 am
Quantumenace wrote:I'd still like to know if it's possible.
I'm not really sure what you're asking for here. All the memory locations in the NPC struct have specific types and uses, you can't just change it by trying to store an NPC object there, which won't work anyway. The closest you can get is storing the index into the NPC array, which is what SMBX usually does when it needs to keep track on an NPC.
RhysOwens wrote:
This was my final code:
Code: Select all local Health = 0
local Health = API.load "HealthPoint";
function onStart()
Health.setNPCHealth(54, 12)
end
Why are you setting your variable to 0 and then to the API you want? There's no reason to set it to 0 first.
|
|
|
|
|
|
|
|
|
-
RhysOwens
- Nipper

- Posts: 423
- Joined: Fri Apr 22, 2016 2:53 am
Postby RhysOwens » Sun Apr 24, 2016 10:04 am
Hoeloe wrote:Quantumenace wrote:I'd still like to know if it's possible.
I'm not really sure what you're asking for here. All the memory locations in the NPC struct have specific types and uses, you can't just change it by trying to store an NPC object there, which won't work anyway. The closest you can get is storing the index into the NPC array, which is what SMBX usually does when it needs to keep track on an NPC.
RhysOwens wrote:
This was my final code:
Code: Select all local Health = 0
local Health = API.load "HealthPoint";
function onStart()
Health.setNPCHealth(54, 12)
end
Why are you setting your variable to 0 and then to the API you want? There's no reason to set it to 0 first.
I heard you had to define the variable first.
|
|
|
|
|
|
|
|
|
-
PixelPest
- Link

- Posts: 7111
- Joined: Sun Jul 12, 2015 5:38 pm
- Flair: Tamer of Boom Booms
-
Contact:
Postby PixelPest » Sun Apr 24, 2016 10:10 am
RhysOwens wrote:I heard you had to define the variable first.
You are by doing local Health = API.load "HealthPoint";
|
|
|
|
|
Return to “LunaLua”
Users browsing this forum: No registered users and 2 guests
|