Implementing jump points (cheat codes) for testing & debugging

Started by Greg Squire, Thu 25/02/2010 23:32:17

Previous topic - Next topic

Greg Squire

How do you guys implement jump points for testing & debugging purposes?  Basically this would be like a cheat code or something that would get you to a certain point in the game so you don't have to always start from the beginning.  This is especially needed in a larger game. 

I thought I could simply use saved games to do this, but I've noticed that if I add another global variable to the game, it seems to invalidate all of my previously saved games.  I'm guessing this is because that variable isn't stored in the old files, but is now expected to be there.  So is there another way to do this?  Or am I just missing something that's already there?

Crimson Wizard

There's no magic way to do this. You'll have to reproduce all (or some, depending on wanted result) the steps player is expected to perform to get to certain point in game's story: set appropriate switches (variables), teleport characters to needed rooms/positions, enable/disable objects, etc, etc, just make it all happen instantly.

It is better to put the code for this in a separate function and call that function by certain key press.

RickJ

You can change what room the game starts in by editing the main character's initial room [parameter  or by editing the game_start() function in the global script.  The put test code in your room to initialize everything to the desired state.


monkey0506

For run-time jump points you could possibly make use of a bitwise mask to pass multiple parameters in at once:

Code: ags
#define DID_THING_A 2 // define each state that should be set as a unique power of 2
#define DID_THING_B 4 // these are for debugging use only
#define DID_THING_C 8
#define DID_THING_D 16
#define DID_THING_E 32

bool thing_a = 0; // some global variables for normal use
bool thing_b = 0;
bool thing_c = 0;
bool thing_d = 0;
bool thing_e = 0;

void DebugJump(int roomID, int flags) {
  thing_a = (flags & DID_THING_A); // this sets our variables based on the flags we passed
  thing_b = (flags & DID_THING_B);
  thing_c = (flags & DID_THING_C);
  thing_d = (flags & DID_THING_D);
  thing_e = (flags & DID_THING_E);
}

function on_key_press(eKeyCode keycode) {
  if (keycode == 'A') DebugJump(5, DID_THING_B | DID_THING_C | DID_THING_E); // jumps to room 5 with things B, C, and E done
  else if (keycode == 'B') DebugJump(20, DID_THING_A | DID_THING_D); // jumps to room 20 with things A and D done
}


That's a wretched example really, but without seeing any of your code..well. It's the basic idea of how a bitmask works. Could prove useful for your case if you have a lot of different variables.

CShelton

Oh and don't forget the built in Debug commands that you can bind to keys:

Debug (0, 0) = give all inventory.
Debug (2, 0) = show walkable surfaces.
Debug (3, 0) = teleport to any room.

I didn't know these existed until I came upon them in the docs. Teleporting is mucho helpful.

SMF spam blocked by CleanTalk