Is there a good way to create a save point in a game?

I want to add an object that allows the player to return to the room it's in when they die, maybe add a penalty for the death, like take away some XP or something. Any way to have an attribute to switch the save point or have a flag to make this work?


i think this will work, not sure.

if (Got(saveobject)) {
if (player.xp = > 10) {
xp = xp - 10
msg ("Your ressurection book saves you from death.")
IncreaseHealth (100)
}
else {
msg ("Your book would've saved you if you had enough XP. You died.")
finish
}
}
else {
msg ("You died.")
finish
}


How about, at the save point, you save the player's stats. Then, when they die, they "wake up" there as they were when they passed that point. Kinda like they triggered something that bumps them back it time.
It would be like they saw the "future" at this point.


yeah, I'm guessing that when you save, it creates a turnscript that every single transaction / action, increases an integer by 1, and then when you wish to load the save it repeats "undo" and subtracts, repeating until 0.


yeah, I'm guessing that when you save, it creates a turnscript that every single transaction / action, increases an integer by 1, and then when you wish to load the save it repeats "undo" and subtracts, repeating until 0.

Why do you need a turnscript?

I think you could do the same thing using a simple integer. When you save, it adds one to the value. And then when you want to return to the save point, it keeps on undoing until the value goes down. If there's a cost for returning to a save point, you would have to apply that cost after all the 'undo' steps. Because "undo" restores the previous value of objects and their attributes, but not local variables.

You could do something like:

if (HasInt (game, "savepoints_reached")) {
  x = game.savepoints_reached
  while (Equal (game.savepoints_reached, x)) {
    undo
  }
}

Or if you only want to be able to go back one savepoint, you could "save" using:

game.is_savepoint = true
start transaction (game)
game.is_savepoint = false

and later return to that point using:

if (HasBoolean (game, "is_savepoint")) {
  while  (not  GetBoolean (game, "is_savepoint")) {
    msg ("Undoing command: {game.pov.currentcommand}.")
    undo
  }

  // insert any XP penalties here
  game.is_savepoint = false
  msg ("Save point reached!")

  // Showing the description might be useful to let the player know where they are
  ShowRoomDescription

  // And you need to refresh the map if you want to  remove any areas that the player hasn't explored yet
  if (GetBoolean (game, "gridmap")){
    Grid_DrawPlayerInRoom (game.pov.parent)
  }

}
else {
  msg ("You haven't reached a savepoint yet.")
}

Log in to post a reply.

Support

Forums