S
Sardec Xavier
Guest
I am trying to save controls and call them back when the game is loaded from an ini file. the controls are set and stored inside the second array correctly, but when accessing them later on, the second array was not set correctly and is just still 0. for instance at global.controlList[0, 5] at the start is set to a number (the index of the button the game uses) however, later on when accessing the same point it returns 0. I cannot figure out why
scr_control_names
scr_default_controls
Code:
///Set up the game
randomize(); // Give me true random
//Set up main menu control for later calls
global.primary_control = 0;
//Set up player controls lists
var buttonTotal = 12;
global.controlList = array_create(4)
global.controlList[0] = array_create(buttonTotal);
global.controlList[1] = array_create(buttonTotal);
global.controlList[2] = array_create(buttonTotal);
global.controlList[3] = array_create(buttonTotal);
controlNames = script_execute( scr_control_names, buttonTotal );
//Check for a load file for previously saved controls
ini_open("control.sav");
//For every player...
for ( var controlId = 0; controlId < 4; controlId++ )
{
var _controlList = global.controlList[controlId];
//Go through every button
for( var loc = 0; loc < buttonTotal; loc++ )
{
// Read in the right controls from the button ID off the save file, if they don't exist, it will give the value of the buttone from a default conrol scheme
var buttonId = controlNames[loc];
var readButton = ini_read_real( "Player: " + string(controlId), buttonId, scr_default_controls( loc ) )
show_debug_message( buttonId + ": " + string(readButton) );
_controlList[loc] = readButton;
ini_write_real( "Player:" + string(controlId), buttonId, readButton );
}
}
//Glose the save file that is open
ini_close();
//Goto the main menu room
room_goto( rm_title_screen );
Code:
// Define the keys inside the Ini file
var arr = array_create( argument0 );
arr[0] = "Shoot"; // Shoot = RT
arr[1] = "Ledge"; // LedgeHang = RB
arr[2] = "Toggle"; // Toggle = Y
arr[3] = "Interact"; // Interact = X
arr[4] = "Jump"; // Jump = A
arr[5] = "Move_Left"; // Move Left = LS
arr[6] = "Move_Right"; // Move Right = LS
arr[7] = "Aim_U"; // Aim Up = LS
arr[8] = "Aim_D"; // Aim Down = LS
arr[9] = "Sprint"; // Sprint = LSB
arr[10] = "Aim_DU"; // Aim Diup = LT
arr[11] = "Aim_DD"; // Aim Didown = LB
return arr;
Code:
///Default control scheme for the game
var defaultList = array_create(12);
defaultList[0] = gp_shoulderrb; // Shoot = RT
defaultList[1] = gp_shoulderr; // LedgeHang = RB
defaultList[2] = gp_face4; // Toggle = Y
defaultList[3] = gp_face3; // Interact = X
defaultList[4] = gp_face1; // Jump = A
defaultList[5] = gp_axislh; // Move Left = LS
defaultList[6] = gp_axislh; // Move Right = LS
defaultList[7] = gp_axislv; // Aim Up = LS
defaultList[8] = gp_axislv; // Aim Down = LS
defaultList[9] = gp_stickl; // Sprint = LSB
defaultList[10] = gp_shoulderl; // Aim Diup = LT
defaultList[11] = gp_shoulderlb; // Aim Didown = LB
//Set Controls
return defaultList[ argument0 ];