u/DystopianTeddyBear

Checking for nearest instances in any direction

Hello! I am in a similar situation to my previous posts; I have an idea of how to get something to work, but I am missing one element to make it work smoothly. The issue I have today is I am looking to find the nearest specific instance in any direction. In theory, all I need is the code below (written as pseudocode)

with(instances){

if point_direction(other.x,other.y,self.x,self.y) = ideal direction

and distance from self to other < stored id

stored id = self
However, I feel like constantly checking possibly a dozen or more objects against each other per room would be a headache. So instead, I have the below code;

if(radar_segment_size != 0){

// Done as to not divide by 0

`for(var dir = radar_dir; dir < 360; dir += 360/radar_segment_size){`

// dir = direction, radar_dir is the starting direction to check for instances according to the original instance.

	`try{`

// That 0,0 in the x2 and y2 is what i need to solve

collision_line_list(self.x,self.y,0,0,checked_object,false,true,radar_objects,true)

//Afterward, make the connection with the first instance in the collision list radar_objects

	`} catch(noInstanceFound){`

	

	`}` 

`}`

// sorry for the messed up code; I still do not know how to get reddit's code block to work... :/}

So with all of that being said, here is my issue:
I need to figure out essentially how to create an x and y value that give the direction of the dir value, while also having the x and y value reach the edge of the room. How do I get that x and y value?

reddit.com
u/DystopianTeddyBear — 3 days ago

Update to Puzzle Game Undo System (questions on depth vs layers, and edge cases with adding instance variables in a struct)

Hello! I don't know if there is any issue to making a new post for a significant update in this subreddit, but I have an update. I finally fixed a major problem with the player and other elements disappearing. However, there are some issues that I'd like some advice on.

I have three questions;

  1. Is it better to utilize depth or layer to manage the way sprites are organized on the screen (the current undo system breaks if both depths and layers are defined, and I have objects that have different depths AND layers)?

  2. If I need to collect instance variables and store them, am I supposed to just create a massive switch case statement to add all instance variables, or is there a better way?

Actual Code:

Once again, I'd like to thank u/germxxx for the code, as I realized the baseline they provided was almost exactly what I needed. Comments are included to note where possible issues are

function save_all(_save_array){

if !is_array(_save_array) exit

var _index = array_length(_save_array)

_save_array[_index] = []

with (all) {

	`if self.persistent continue // Included to not have errors with a music loader, but the camera object maybe should be included?`

var _struct = {id, depth, // Error with player and ui objects if layer is included since i have the depth values set to a value with no layer, and potential error if layer is not included since another object utilizes a layer system to determine what instance of the object is active.

x, y, sprite_index, image_xscale, image_yscale} // Self and global variables are not edited. idea to seperate the structfor each and array push from the standard struct to make room for a switch / case statement after the with all, but that sounds... inefficient.

struct_foreach((self), method({_struct} ,function(_name, _value) {

_struct[$ _name] = _value

}))

array_push(_save_array[_index], _struct)

}

}

function load_all(_save_array) {

/* Something here breaks in many ways; the first undo does not properly undo the last move, and if multiple undos are made inbetween moves, the undos I think stop at the moment after the most recent undo; e.g. Initial (state 0) -> Move (state 1) -> Move (state 2) -> Undo (possibly state 2? seemingly does not work) -> Undo (state 1, works) -> Move (new state 2) -> Undo repeat (sends to state 1 and never state 0)

*/

`if(array_length(_save_array) = 0) exit`

var _data = array_pop(_save_array)

for (var i = 0; i < array_length(_data); i++) {

var _variables = struct_get_names(_data[i])

for (var j = 0; j < array_length(_variables); j++) {

var _name = _variables[j]

if _name = "id" continue

variable_instance_set(_data[i].id, _name, _data[i][$ _name])

}

}

}

reddit.com
u/DystopianTeddyBear — 7 days ago

Puzzle Game Undo System

I've been working on a puzzle game for a few months now, and I'm finally ready to tackle one of the main challenges I was concerned about with the genre; the undo system. I've gotten the idea to use the ideas discussed in the post "save all objects in a room" from this subreddit, but I don't know how I can create possibly dozens of save states that allow for undoing (akin to Patrick's Parabox or Baba is You). Current code is listed below;

EDIT; my original code was messed up, so I have now changed it to be more correct. Thank you to u/germxxx for the better code translation.

global.room_objects = {index: []};
// On a click of the interact button;

with (all) {
  if (self != other) {
    // done to try and not have recursive structures, which seemingly do not work

    variable_strings = variable_instance_get_names(self.id);
    variable_vals = [];

    for (var i = 0; i < array_length(variable_strings); i++) {
      variable_vals[i] = variable_instance_get(self.object_index,variable_strings[i]);
    }

    variable_struct_set(global.room_objects,global.room_objects.index,variable_vals);
  }
}

One final note;

My idea for loading the data is to delete all objects, then create objects based on the previous state of the game, with the values listed for that object for that state. Depending on the complexity of the code however, I may need advice to structure that part as well.

reddit.com
u/DystopianTeddyBear — 11 days ago