Certainly, let's review the corrected code thoroughly to ensure all potential issues are addressed. I will go through the code section by section, identify possible problems, and fix them.
-
Correcting the Use of ord():
Ensure that ord() is correctly used within conditions, using parentheses appropriately.
-
Variable _element Scope Check:
Ensure _element is correctly checked for element_selected condition.
-
Fixing Syntax for Struct Operations:
Ensure that struct_exists and struct_remove are correctly used.
-
Ensure Proper Function Calls:
Guarantee that function calls like mouse_wheel_up, mouse_wheel_down, etc., are correct and available in the environment.
Here's a step-by-step refined version of your code with corrections and comments:
if (global.debug) {
return;
}
// Mouse position retrieval
mx = window_mouse_get_x();
my = window_mouse_get_y();
// Toggle edit mode
if (keyboard_check_pressed(vk_f1)) {
edit_mode = !edit_mode;
}
if (!edit_mode) {
return;
}
// Toggle view all mode
if (keyboard_check_pressed(ord("V"))) {
view_all = !view_all;
}
// Element selection and processing
if (element_selected != -4) {
var _element = ds_list_find_value(global.list_elements, element_selected);
// Increment speed
if (keyboard_check_pressed(ord("I"))) {
if (_element.row == 0) {
_element.spd++;
if (_element.spd > 2) {
_element.spd = 0;
}
}
}
// Grid settings input
if (keyboard_check_pressed(ord("G"))) {
grid_x = get_integer("grid_x:" + string(grid_x), "");
grid_y = get_integer("grid_y:" + string(grid_y), "");
}
// Path asset input
if (keyboard_check_pressed(ord("P"))) {
var _str = get_string("Enter Path Asset Name", "");
if (path_exists(asset_get_index(_str))) {
_element.mypath = _str;
_element.path_pos = 0;
show_message("Path Set!");
_element.x = path_get_x(asset_get_index(_str), 0);
_element.y = path_get_y(asset_get_index(_str), 0);
} else if (struct_exists(_element, "mypath")) {
struct_remove(_element, "mypath");
}
}
// Toggle wings
if (keyboard_check_pressed(ord("F"))) {
if (!struct_exists(_element, "wings")) {
_element.wings = false;
}
_element.wings = !_element.wings;
}
// Landing ID input
if (keyboard_check_pressed(ord("L"))) {
var _str = get_integer("Enter Landing ID", "");
if (_str != -4) {
_element.land_id = _str;
} else if (struct_exists(_element, "land_id")) {
struct_remove(_element, "land_id");
}
}
// Space key actions
if (keyboard_check_pressed(vk_space)) {
if (_element.row == 4) {
if (_element.ind == 0) {
if (keyboard_check(vk_shift)) {
var _str = get_integer("Enter Channel Wait", "");
if (_str != -4) {
_element.wait = _str;
} else {
_element.wait = -4;
}
} else {
_str = get_integer("Enter Channel ID", "");
if (_str != -4) {
_element.channel = _str;
} else {
_element.channel = -4;
}
}
} else if (_element.ind == 2) {
_str = get_string("Enter Wizard Sprite", "");
if (_str != -4) {
_element.spr_change = _str;
} else {
_element.spr_change = -4;
}
}
}
if (_element.row == 5) {
if (_element.ind == 1) {
_str = get_integer("Enter Lights-Out Length\n(In Seconds Not Frames)", "");
if (_str != -4) {
_element.length = _str;
} else {
_element.length = 2;
}
} else if (_element.ind == 2) {
_str = get_integer("Enter Fireball HSPD", "");
if (_str != -4) {
_element.hspd = _str;
} else {
_element.hspd = 2;
}
}
}
if (_element.row == 6) {
if (_element.ind == 0) {
_str = get_string("Enter Sound Name", "");
if (_str != -4) {
_element.snd = _str;
} else {
_element.snd = "undefined";
}
}
}
}
// Adjust timestamps and positions
var _yAxis = keyboard_check_pressed(vk_down) - keyboard_check_pressed(vk_up);
if (_yAxis != 0) {
if (keyboard_check(vk_shift)) {
_element.timestamp += (_yAxis * 30);
} else {
_element.timestamp += (_yAxis * 60);
}
}
var _xAxis = keyboard_check_pressed(vk_right) - keyboard_check_pressed(vk_left);
if (_xAxis != 0) {
if (keyboard_check(vk_shift)) {
_element.cx += (_xAxis * 40);
} else {
_element.cx += (_xAxis * 20);
}
}
// Timestamp input
if (keyboard_check_pressed(ord("T"))) {
var _int = get_integer("Enter Second (NOT Game Frame)", "") * 60;
if (is_numeric(_int)) {
_element.timestamp = _int;
}
}
}
// JSON export on return key
if (keyboard_check_pressed(vk_return)) {
var _data = ds_map_create();
var _list = ds_list_create();
ds_list_copy(_list, global.list_elements);
ds_map_add_list(_data, "elements", _list);
var _str = json_encode(_data);
show_debug_message(_str);
clipboard_set_text(_str);
ds_map_destroy(_data);
ds_list_destroy(_list);
}
// Path position adjustments
var x1 = 1011;
var y1 = 1006;
var x2 = x1 + 397;
var y2 = y1 + 74;
if (element_selected != -4 && struct_exists(_element, "mypath") && point_in_rectangle(mx, my, x1, y1, x2, y2)) {
if (mouse_wheel_down()) {
_element.path_pos -= (0.01 + 0.03 * keyboard_check(vk_shift));
}
if (mouse_wheel_up()) {
_element.path_pos += (0.01 + 0.03 * keyboard_check(vk_shift));
}
if (_element.path_pos < 0) {
_element.path_pos = 1;
}
if (_element.path_pos > 1) {
_element.path_pos = 0;
}
} else {
// Scroll handling
if (mouse_wheel_down()) {
scroll_y -= (30 + 30 * keyboard_check(vk_shift) * 8);
}
if (mouse_wheel_up()) {
scroll_y += (30 + 30 * keyboard_check(vk_shift) * 8);
}
}
Additional Notes:
- Ensure that all GML functions like
mouse_wheel_down, mouse_wheel_up, keyboard_check_pressed, etc., are correctly invoked and supported.
- Ensure the variables and functions like
element_selected, global.list_elements, is_numeric, path_exists, and asset_get_index are correctly defined elsewhere in your project.
Please try the above-refined code and let me know if there are any specific errors or issues you encounter. If the problems persist, sharing the exact error messages would help in further diagnosing the problem.