[SOLVED] Special debug commands: Changing variables, moving characters and more

Started by Glenjamin, Fri 03/08/2018 19:52:31

Previous topic - Next topic

Glenjamin

Not really sure where to draw the line between begginer and advanced technical questions, so here we go.

I want to make an in-game GUI that allows me to modify variables while playing. Similar to the built in debug commands. This is for testing particularly large games.

Of course building the gui is simple enough, it's the code I don't know how to tackle.

Ideally, this gui could manipulate the following:


  • Global variables
  • Character rooms/coordinates
  • Run scripts(Maybe)
  • Add specific items to the inventory
  • Refresh the current room so characters/objects can react according to the current script


Of course there's the long way of doing this, like making a button for every inventory item, but can't help but think there's a smarter way to handle it.

If I can make it work, I'd be happy to publish it as a module so everyone can test their more complex games faster.




dayowlron

modifying Global variables and running scripts would be almost impossible to do as a "generic" gui.
Not sure what you mean by the last one because you can't change a script when the game is running.
However the changing character rooms, and coordinates along with adding or removing inventory items could be done as a generic script.
I would use an inventory window OR a listbox to show the different inventory items along with an add to inventory and remove from inventory buttons. Change room and coordinates would just be textboxes and buttons to execute the command.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Buckethead

Getting a listbox with all the inventory items in the game, that you can add/remove to the player's inventory, is very possible.

Get all the items into the listbox on your GUI.
Code: ags

function game_start() 
{
    for (int i = 1; i < Game.InventoryItemCount + 1; i++)
        lbInventory.AddItem(inventory[i].Name);

}


Add/remove an inventory item:
Code: ags

function btnGiveInv_OnClick(GUIControl *control, MouseButton button)
{
    player.AddInventory(inventory[lbInventory.SelectedIndex + 1]);
}

function btnRemoveInv_OnClick(GUIControl *control, MouseButton button)
{
    player.LoseInventory(inventory[lbInventory.SelectedIndex + 1]);
}


You can't really do something similar for Global variables though. There's no way to know how many global variables exist and what they are (script wise). So you will have to do those manually.

There is a function to reset a room but it can't be the current room unfortunately. What you could do is make room for debugging and change the current room to that. Then in that room do something like this:
Code: ags

function room_AfterFadeIn()
{
    ResetRoom(RoomToReset);
    player.ChangeRoom(RoomToReset);
}


Where "RoomToReset" is a global int that you set to the current room before you change.

Slasher

I did some similar things in my game of fishing some time back where you have an in-game gui to change fishing tackle and things...

http://www.adventuregamestudio.co.uk/site/games/game/2041/

SMF spam blocked by CleanTalk