Looking back, the coroutines in that paste definitely won't work because they're calling functions with walkDirWithBreak() in them, but, uh, you get the general idea.
I can see how this potentially could cause some issues, so if you think it's still a bad idea then I'm up for dropping coroutine Actor commands. But what about cutscenes/boss AI/other sequences? Are those okay or is it best to just stick to the current implementation or something else entirely?
Hope this doesn't sound snappy or sarcastic or anything. It's been clear from day one that I'm far from being the best programmer around here, I'm just one of the more ambitious and thick-headed/impulsive/whatever ones
Oh, almost forgot, I started working on constants for the NPC IDs. Dunno if someone else has already done this so I may just be wasting my time, buuuuuut...
Rockythechao wrote:
I can see how this potentially could cause some issues, so if you think it's still a bad idea then I'm up for dropping coroutine Actor commands. But what about cutscenes/boss AI/other sequences? Are those okay or is it best to just stick to the current implementation or something else entirely?
What you've suggested is a solution, but it's a bit of a hacky one. I suggest dropping commands from coroutines that might need to be interrupted - coroutines aren't built for that kind of functionality, and it gets messy. To be honest, I think if people want to use coroutines, let them use them in Lua, rather than disguising them behind function calls. You don't lose any functionality this way, and people can still stick code into coroutines themselves, but it ensures that the programmer knows when their code is doing things in the background and when it isn't, which makes their job much easier.
Re: Presenting: Lunadll for Lua!
Posted: 05 Oct 2014, 03:54
by Rixithechao
Aaaaaand I finally looked at the source, not sure what led me to believe that the Player and NPC classes were defined in Lua themselves. So that pastebin was even less help than I initially thought it'd be...
Well, I've gone and split up the code between lapi, lunaworld and lunadll in such a manner that it won't work without require() and it'd be too much trouble to throw everything back into lunadll.lua, so for the time being the cutscene and battle stuff is all commented out while I work on the HUD elements... and placeSprite() doesn't seem to be working.
function onLoad ()
IMG_LETTERBOX = 0
IMG_BOSSHP_RIGHT = 1
IMG_BOSSHP_LEFT = 2
IMG_BOSSHP_EMPTY = 3
IMG_BOSSHP_FULL = 4
IMG_BOSSHP_BG = 5
loadImage ("letterbox.bmp", IMG_LETTERBOX, 0xFF00DC)
loadImage ("bossHP_right.bmp", IMG_BOSSHP_RIGHT, 0xFF00DC)
loadImage ("bossHP_left.bmp", IMG_BOSSHP_LEFT, 0xFF00DC)
loadImage ("bossHP_midE.bmp", IMG_BOSSHP_EMPTY, 0xFF00DC)
loadImage ("bossHP_midF.bmp", IMG_BOSSHP_FULL, 0xFF00DC)
loadImage ("bossHP_bg.bmp", IMG_BOSSHP_BG, 0xFF00DC)
end
function onLoop ()
-- Display cutscene UI elements
processCutsceneUI ()
debugCounter = (debugCounter + 1) % 120
if debugCounter == 0 then
currentSceneState = (currentSceneState + 1) % 4
playSFX (2)
end
end
function processCutsceneUI ()
placeSprite (1, IMG_LETTERBOX, 0, 0)
-- BOSS HP BAR
if currentSceneState == SCENESTATE_BATTLE then
-- Bar BG
placeSprite (1, IMG_BOSSHP_BG, player.screen.left, player.screen.top, "", 1)
-- Bar sides
local barLeft = player.screen.left + 400 - (bossHPMax * 16)
local barRight = barLeft + (bossHPMax * 32)
local barY = 520
placeSprite (1, IMG_BOSSHP_LEFT, barLeft, barY, "", 1)
placeSprite (1, IMG_BOSSHP_RIGHT, barRight, barY, "", 1)
-- Bar units
for i = 0, bossHPMax-1 do
local sprX = barLeft + (i+1)*32
local sprImg = IMG_BOSSHP_EMPTY
if (i <= bossHP-1) then
sprImg = IMG_BOSSHP_FULL
end
placeSprite (1, sprImg, sprX, barY, "", 1)
end
-- Boss Name
printCenteredText (bossName, 4, 400, 500)
-- CUTSCENE LETTERBOXING
elseif currentSceneState == SCENESTATE_CUTSCENE then
placeSprite (1, IMG_LETTERBOX, 0, 0, "", 1)
-- TEXTBOXES DURING GAMEPLAY
elseif currentSceneState == SCENESTATE_PLAY then
end
-- DISPLAY DIALOGUE/SUBTITLES
if dialogTextTime > 0 and (currentSceneState == SCENESTATE_PLAY or currentSceneState == SCENESTATE_CUTSCENE) then
printText(dialogName..":", 4, 5, 475)
printText(string.sub(dialogText, 0, 43), 4, 15, 495)
printText(string.sub(dialogText, 44, 87), 4, 15, 515)
printText(string.sub(dialogText, 88, 131), 4, 15, 535)
printText(string.sub(dialogText, 132, 175), 4, 15, 555)
if(dialogEndWithInput == true) then
printText("(PRESS X TO CONTINUE)", 4, 400, 580)
end
end
end
It's cycling through the different scene states but the only thing that gets displayed is the Boss' name. I've tried changing the coordinates, the sprite type, resource indexes, no matter what they won't show up.
Re: Presenting: Lunadll for Lua!
Posted: 05 Oct 2014, 09:32
by Kevsoft
LunaLua v0.2.6.1 is out
Changes:
* Added package lib
* lapi.lua can now run independet without having the level file in 'world/project' folder.
Rocky, you should now be able to use the package lib.
Re: Presenting: Lunadll for Lua!
Posted: 05 Oct 2014, 16:30
by Rixithechao
Arright, after much trial and error I got the require() calls working. Quick overview of the stuff so that others don't get stuck on it:
Lua doesn't like to keep track of relative directory paths. Instead it searches through your system for paths that match or contain at least one of the patterns stored in the variable package.path. So in order to get your script to access the files(s) you want, you have to add patterns to package.path. Then you simply call require (script name minus .lua).
I'm still not 100% clear on the pattern formatting, but from what I've gathered semicolons mark the beginning of a pattern, question marks are wild cards, "./" means one folder forward, "../" seems to mean one folder back and "..." means "please crash the SMBX editor". And Lua uses '..' to concatenate strings instead of '+'.
Basically, just write it like this and things probably won't break. Probably.
loadImage and placeSprite still don't do anything for me. I haven't change my HUD code since the last post, and going by both Kil's Phanto tutorial and Darkchao's custom HUD tutorial, it all seems to check out.
Re: Presenting: Lunadll for Lua!
Posted: 05 Oct 2014, 17:23
by Kevsoft
Rockythechao wrote:loadImage and placeSprite still don't do anything for me. I haven't change my HUD code since the last post, and going by both Kil's Phanto tutorial and Darkchao's custom HUD tutorial, it all seems to check out.
Do you recive any error message, or does it simply not work?
Re: Presenting: Lunadll for Lua!
Posted: 05 Oct 2014, 17:53
by Rixithechao
Same as the earlier post, it cycles through the different states properly but it only displays text.
Re: Presenting: Lunadll for Lua!
Posted: 05 Oct 2014, 21:23
by Kil
That should work, but I think there's a bug with builtin placesprite with the way you're trying to use it that prevents it from displaying.
Re: Presenting: Lunadll for Lua!
Posted: 07 Oct 2014, 20:52
by SAJewers
Not sure if this is possible with Lua, but I think It'd be pretty cool if someone made something like this for Episode 2:
Re: Presenting: Lunadll for Lua!
Posted: 07 Oct 2014, 21:08
by Willhart
There has been some semi 3D trickery done with default smbx graphics and events. The example there might be useful for making tunnel type stages. I wonder if it could be improved somehow.
SAJewers wrote:Not sure if this is possible with Lua, but I think It'd be pretty cool if someone made something like this for Episode 2
Do you mean only the raw gameplay-style or the whole 3d-vector-style with it?
Willhart wrote:There has been some semi 3D trickery done with default smbx graphics and events. The example there might be useful for making tunnel type stages. I wonder if it could be improved somehow.
Improved with lua? How would you improve it?
Re: Presenting: Lunadll for Lua!
Posted: 08 Oct 2014, 13:23
by Kil
I'm sure someone could make a stage like that if they just got an animated background and hooked up a sprite or layer or something to the player input.
Re: Presenting: Lunadll for Lua!
Posted: 08 Oct 2014, 22:18
by Holy
Okay, I have no idea what I'm doing.
I'm trying to make the player sparkle only when they're moving. This is my attempt:
function onLoop()
if(player.y ~= 0) then
player:mem(0x02,player,0xFFFF)
elseif(player.x ~= 0) then
player:mem(0x02,player,0xFFFF)
else
player:mem(0x02,player,0)
end
end
-- PlayerMemSet,0,0x02,0xFFFF,0,0,w
-- PlayerMemSet,0,0x02,0,0,0,w
But that don't work. I'm sure it's some giant thing I'm missing here.
Re: Presenting: Lunadll for Lua!
Posted: 08 Oct 2014, 23:15
by Hoeloe
Holy wrote:
But that don't work. I'm sure it's some giant thing I'm missing here.
Looks like you're checking the player's position, rather than the player's speed.
Also, fundamentally, 3D is very similar to 2D. That kind of style should be perfectly possible with a bit of vector maths to work out the relative position and scale of objects from a variable storing their z coordinate. It would take a hell of a lot of work to do this properly, for everything on screen, though.
Re: Presenting: Lunadll for Lua!
Posted: 08 Oct 2014, 23:40
by Holy
Ooh, yeah, thanks.
I also had to change the constant "player" to "FIELD_WORD", and now it works!
Re: Presenting: Lunadll for Lua!
Posted: 09 Oct 2014, 01:35
by Rixithechao
Arright, here's most of the NPC ID constants (everything but the SMW page) formatted so you can copy & paste them directly into LunaLuaMain.cpp.
So, I'm looking at making a level that starts with a short cutscene. I'm not sure, however, how to spawn in the different possible players (so that they can converse in the cutscene). I know I could do this by overriding an NPC, but I'm wondering if there's a better way to do it than that. I'm quite new to LunaDLL - I haven't used it much before, mainly because of the horrific syntax. Now that Lua is available, I'm trying my hand at it, and I'm not really sure how it all works.
One thing I do recommend is beefing up the documentation a bit. Here's an example, from one of the "placeSprite" functions:
Places a image/sprite by resource-number imgResource at xPos, yPos. Extra string data field provided. Leave a empty string if not used. You can set the time if needed.
Aside from not making it entirely clear how resource-numbers work, there are issues with the latter half of this description. You've said "extra string data field provided", but what does that actually do? "Extra string data" could be literally anything. Why is it there, what is it for? As well as this there's also "You can set the time if needed". The time of what? The time at which the image will be placed? The duration it stays on screen?
There are other things too, such as valid values for arguments (inserting 21 when looking for a section will crash the game, for example). I strongly recommend some more informative documentation. It will make LunaLua so much easier to use.
P.S. I've been trying to work out how to disable player movement while retaining the ability to progress cutscenes. So far, I've managed to stop the player moving by continually resetting their position and speed, but they can still change direction, jump (only one pixel, but the sound plays), and crouch. They are also stuck in the jumping animation.
Re: Presenting: Lunadll for Lua!
Posted: 10 Oct 2014, 19:07
by Hoeloe
Ah, I'm getting somewhere with blocking the player input. I've got it to work under 2 conditions: 1. The player doesn't move while the input is disabled and 2. the player has invincibility frames when input is enabled.
I've also noted that the variable named Unknown124 has interesting effects when used with ForceAnimationState - this is how I was achieving freezing player input. I think there must be a better solution though, as this is very buggy.
On an unrelated note, I'm trying to improve the text box system that we saw in the Broadsword fight, by using either a foreground npc or placeSprite to draw the textbox. This means it will not only follow the camera, but can be disabled at will, and that levels can be built with it still present. It seems that placeSprite doesn't work at all, but I'm wondering if there is a way to get the x and y coordinates of the screen, in order to place an NPC relative to the movement of the screen as it follows the player.
EDIT: Ah! I got placeSprite working! It just has to be a bmp file. It does produce a lot of lag if you use it onLoop though, and it seems you may not be able to remove it once it's placed, which is a shame.
EDIT EDIT: Player.kill() doesn't appear to work. It throws an error saying: No matching overload found.
Wait, I'm just dumb and too used to C# syntax. Player:kill() works. It does, however, lack a check for whether the player is already dead, so you get an infinite chain of dead players.
Re: Presenting: Lunadll for Lua!
Posted: 10 Oct 2014, 21:04
by Hoeloe
SUCCESS! I've got a text box that can be toggled at will, and will nicely display at the bottom of the screen regardless of the section.
It required two .bmp images, one is 800x128, solid black, called "textbox.bmp", the other is a single solid white pixel, called "emptyBox.bmp".
The colours of the images don't actually matter, except in the case of loading emptyBox, in which case the hex code must be the same colour as the pixel in the image.
With an additional bit of poking around, you can also make it so you die if you fall below the text box boundary, rather than having to fall all the way through it:
if(player.y > player.sectionObj.boundary.bottom - 96 and player:mem(0x13C, FIELD_FLOAT) == 0) then
player:kill();
end
Re: Presenting: Lunadll for Lua!
Posted: 10 Oct 2014, 22:29
by Hoeloe
Hmm... having issues controlling animation of NPCs. I'm using the Broadsword battle as a base, but at the moment I'm just trying to play an animation at will. It seems to continuously get stuck on the first frame of the animation, unless I set the animation multiplier in the NPC config file to something other than 1, in which case it flickers, but doesn't play... Any idea why this might be happening?
EDIT: As it turns out, I'm once again just a moron. Forgot to remove some old code that constantly reset the frame number.
Sorry for all these messages, by the way.
Re: Presenting: Lunadll for Lua!
Posted: 10 Oct 2014, 22:59
by Rixithechao
So I am really regretting taking so long to type these posts.
TROUBLES WITH THE BROADSWORD NPC:
Sorry about that, I should've included the other stuff with that old pastebin. I used npc code files for the different components of Broadsword. I'll have them up on Google Drive in a bit.
DOCUMENTATION:
Completely agree. If you look at the help files for software like GameMaker or Unity, they usually give each function their own dedicated page breaking down how to use it, including visual aids and example code. You might not need that much detail for every function but a bit more information couldn't hurt.
INPUT/FREEZING THE PLAYER DURING CUTSCENES:
I have a somewhat hacky, roundabout idea. Perhaps when switching to cutscene mode it could store the player's powerup state, then set it to 8 or above to make them invisible and snap them to an NPC or sprite... I'm getting a major sense of deja vu here, have I suggested this before?
But, uh, yeah, stuff the player in an actor during cutscenes, give the actor the player's appearance and then swap them back out when the cutscene ends.
SPAWNING ACTORS AND OVERRIDING NPCS:
Blargh CSprite class I don't know how to phrase this bit
Rockythechao wrote:
INPUT/FREEZING THE PLAYER DURING CUTSCENES:
I have a somewhat hacky, roundabout idea. Perhaps when switching to cutscene mode it could store the player's powerup state, then set it to 8 or above to make them invisible and snap them to an NPC or sprite... I'm getting a major sense of deja vu here, have I suggested this before?
This seems to be the ideal way to do this. I don't know all the details of the LunaDLL functions, but would it be possible to use placeSprite for this?
Oh, and yeah, sorry for all the posts ranting and going off on a tangent. Programming in a language I've never used before with a splitting headache doesn't seem to go too well.
Hmm... still getting that flickering on my idle frame, though. Weird.
Re: Presenting: Lunadll for Lua!
Posted: 10 Oct 2014, 23:16
by Rixithechao
Unless someone's typing in all caps (and in that last post I was just frantically doing it for emphasis) or using really harsh language it never comes across to me as ranting, just stern disapproval.
there was no message box system at all in the Broadsword fight, I just put those SMB3 black blocks there until I could get one to work. Though, technically I was going for letterboxing + subtitles.
I'm thinking for the hud elements we should have a function that does a bitblt() call to paint the image directly to the screen for that frame.
EDIT: The flickering you're referring to is probably due to a bug with the old animation management system, you needed a duplicate of the last frame as a buffer.
Re: Presenting: Lunadll for Lua!
Posted: 10 Oct 2014, 23:28
by Hoeloe
Rockythechao wrote:
there was no message box system at all in the Broadsword fight, I just put those SMB3 black blocks there until I could get one to work. Though, technically I was going for letterboxing + subtitles.
Well, I've got one set up now, if you want to steal it for purposes.
Rockythechao wrote:
EDIT: The flickering you're referring to is probably due to a bug with the old animation management system, you needed a duplicate of the last frame as a buffer.
Ah, that makes sense. By the way, I'm trying to implement this with the (frankly much neater) system you have set up using the lunaworld dll, but it is complaining about a lack of cinematX files. Can I get hold of those from somewhere?
Re: Presenting: Lunadll for Lua!
Posted: 10 Oct 2014, 23:34
by Rixithechao
Oh, jeez, my bad! cinematX is what I decided to call the library/API, so all of the management functions are -- or at least should be -- in there. It's up on the drive now, but fair warning, it's super-broken/incomplete.
The end goal is that you only have to call cinematX.init() in onLoad() and a cinematX.update() function in onLoop() within lunadll.lua, everything else will be handled by cinematX and lunaworld.
Okay, between the files on gdrive and the old pastebin you should have everything now. I really don't want to leave you with such a broken mess but I ended up spending all day writing the responses on the talkhaus and now I have just under 12 hours to finish and submit my comp sci homework >_<