Post new topic    
Liquid Metal Slime
Send private message
script debugging help 
 PostSun Mar 24, 2013 2:28 am
Send private message Reply with quote
The script below causes every hero up to 20 damage (randomized) and then checks to see if any of them are still alive. If none are still alive, the script causes are a game over.

This works perfectly if I have 2 or more heroes in the party. However, if I only have 1 hero, that single hero can reach 0 HP without causing a game over.

Code:
plotscript, crest1, begin
map cure (31, 0)
map cure (31, 1)
map cure (31, 2)
map cure (31, 3)
variable (i, hpleft, someone alive)
someone alive := false
for (i, 0, 3) do (
  hpleft:= get hero stat(i, stat:Hull, current stat)
  if (hpleft>> 0) then (someone alive := true)
)
if (someone alive == false) then (
  show text box (109)
  wait for text box
  show backdrop (0)
  show textbox (235)
  wait for text box
  game over
)
show text box (110)
end


Here's where things get weird. The scripts listed below run as part of the ship selection screen. If I select the bomber ship (running the blank addbomber script), the bug described above does not seem to manifest. However, if i select the carrier or the fighter (thereby running addcarrier or addfighter), then the bug does appear.

Code:

plotscript, addbomber, begin
end

plotscript, addcarrier, begin
add hero (hero:carrier)
swap by position (0,1)
delete hero (hero:bomber)
end

plotscript, addfighter, begin
add hero (hero:fighter)
swap by position (0,1)
delete hero (hero:carrier)
end


The bug will appear if I am using the bomber, If I rewrite bomberscript as:

add hero (hero:bomber)
swap by position (0,1)
delete hero (hero:bomber)

Therefore, it seems to have something to delete here command. Does anyone have any idea?
Metal King Slime
Send private message
 
 PostSun Mar 24, 2013 2:37 am
Send private message Reply with quote
Perhaps instead of "hpleft >> 0" you could use "hpleft >= 0" ? I'm not sure if it would make a difference though.


Though I have no idea why the second script would interfere with it. The first script looks pretty straightforward to me, I'm not sure why it would fail. My guess is that there's a problem with checking the amount of HP, but I could be pretty far off the mark.
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Metal King Slime
Send private message
 
 PostSun Mar 24, 2013 5:14 am
Send private message Reply with quote
Do you have some kind of a placeholder hero until the character has chosen a bomber, carrier or fighter, something that could still be in the party somehow?

EDIT: Oh! You might also try adding a wait after the 4 "map cure" commands. Maybe it isn't giving it a chance to update the stat before it checks it? Doesn't explain why it screws up if you use the add bomber thing though.
Metal King Slime
Send private message
 
 PostSun Mar 24, 2013 9:57 am
Send private message Reply with quote
It appears that you've discovered a bug, though not the one that you think you have. "map cure" is meant to check if it the whole party is dead and if so run the death script. (much poking around...) Oh dear, this is a really serious bug. For the last 18 months, including Alectormancy, checking whether you've killed your party outside of battle (with harm tiles, items, spells, or "map cure") has not worked. Fixed now, though I notice another problem in the game over code...

To answer your question about why your script is misbehaving, it's because of an obscure feature of getherostat which exists for backwards compatibility: nonexistent heroes have stats too. After you delete a hero, using getherostat on the slot that it was in continues to return the removed hero's stats. So your for loop sees a phantom hero with non-zero HP.

It's always a good idea to add checks such as whether there is actually a hero in a party slot rather than assuming it's ok to pass invalid arguments to a command. Your loop should look like:

Code:
for (i, 0, 3) do (
  if (hero by slot(i) > -1) then (
    hpleft:= get hero stat(i, stat:Hull, current stat)
    if (hpleft > 0) then (someone alive := true)
  )
)


Anyway, to answer the actual question, assuming that those textboxes don't show the same thing as your default gameover script, download the next nightly (not right now) and do:

Code:
plotscript, crest1, begin
  set death script (@crest death script)
  map cure (31, 0)
  map cure (31, 1)
  map cure (31, 2)
  map cure (31, 3)
  wait(1)  # Necessary to allow the death script to be triggered
  # continues if not dead...
  set death script (@whatever the default death script is)
  show text box (110)
end
 
script, crest death script, begin
  show text box (109)
  wait for text box
  show backdrop (0)
  show textbox (235)
  wait for text box
  game over
end


There's a number of other options, like putting that in the existing gameover script instead.
Liquid Metal Slime
Send private message
 
 PostSun Mar 24, 2013 11:38 pm
Send private message Reply with quote
TMC wrote:

Code:
for (i, 0, 3) do (
  if (hero by slot(i) > -1) then (
    hpleft:= get hero stat(i, stat:Hull, current stat)
    if (hpleft > 0) then (someone alive := true)
  )
)


Implementing this script eliminated the bug, for my purposes at least.

I'm going to release v1.1 of Dreg Sector this week. I can't thank you enough for the help you have provided squashing the game's bugs. This new version should be vastly improved and it's mostly thanks to your work.
Metal King Slime
Send private message
 
 PostMon Mar 25, 2013 12:24 am
Send private message Reply with quote
No, don't do that, it'll break when you switch to Beelzebufo.
Liquid Metal Slime
Send private message
 
 PostMon Mar 25, 2013 2:23 am
Send private message Reply with quote
TMC wrote:
No, don't do that, it'll break when you switch to Beelzebufo.


Cool. Instead, I'll update to the newest nightly when it's posted. Although, I doubt I would bring this project into Beelzebufo anyway.
Metal King Slime
Send private message
 
 PostMon Mar 25, 2013 2:39 am
Send private message Reply with quote
Nightlies are built automatically, twice a day, I think. The fix for that bug is available already.

You are using Beelzebufo already, it just isn't official! Unless you mean you'll stick with Zenzizenzic and adapt your script. Writing scripts in a way that's known to break in later engine versions is definitely a bad idea.

You could actually have your script work on all versions by changing the ondeath script to a blank script at the start and restoring it at the end.
Display posts from previous: