• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

My Many Questions, still new incomming

V

vinceprinceking

Guest
Edit 26.09.2016:
Questions 1-6 solved, thx for all the help guys, really appreciate it.
Questions 7-11 still clueless here, pls help me ;)

Original Post:
Hi guys i'm using game maker for a few days and still in the process of learning. Thanks in advance for solution to my questions:

1. can you destroy a specific instance from within another object? something like (instance_id).instance_destroy() doesn't work.
My solution is to have a step event inside the object i wanna destroy with: "if (variable_destroy) instance_destroy();" and i set the "(instance_id).variable_destroy = true" inside the other event. But this means several hundreds of instances are all running this step event nonstop which seems quite unnecessary.

2. How does the Parent-Ancestor relationship work? If you for example check "id =instance_place(x,y, o_Parent)" does GameMaker check for Ancestor instances too? If not can you somehow make him do that?

3.if the instance_place() would in theory get more than one instance at the same time, how is it possible to get all ids and store them in an array or something.

4. In the following code i try to see if some obj o_Parent_Usable or some of its Childs is on a certain position, afterwards i want to do specific if its o_Child1 o_Child2 o_Child3 and so on. Am i doing it right? code isnt working right now. any suggestions? Or do i have to check for postion_meeting for every child on its own?

Code:
if position_meeting(x+xx,y+yy,o_Parent_Usable){

var ID_Of_Instance = instance_position(x+xx,y+yy,o_Parent_Usable);

if object_get_name(ID_Of_Instance) == "o_Child" {
scr_DoStuffwith(ID_Of_Instance)
}}

5. can i save a room-id in a varable so i can teleport back later?

6. can i toggle persistence of a room on and off with code?​


Edit: 26.09.2016
great thanks and here are the next questions:

7. so in the following code n returns true? so a Variable always returns true if its not -4, noone, 0 ??? Or is it just with Instance IDs? How exactly does that work?
[QUOTE="TheouAegis, post: 58913, member: 1973"
var n = instance_position(x+xx,y+yy,o_Parent_Usable);
if n scr_DoStuffWith(n);
[/QUOTE]

8. I know i can make a script return a boolean or a variable value. Can i make it return more than one? My solution would be to make a big string with ";" in between values, then make some script in a loop return values out of the string again. Is there a better solution?

9.Also what commands to get values back out of strings in general?

10. I got this Array right now where i store Item specific stuff like: "Name" (string), "Able_To_Pickup" (boolean), "MaxItemInPossesion" (int), "Able_To_Gift" (boolean)..., or if i had one for each specific NPC where all his "important" Values get stored. Where should i store Data like that, and Controller_Object, an .ini file, globals, and so on? I'm not talking about saving, just storing while the game runs. Are there rules when to use what and what is the most suited?

11. I have some screen tearing / flickering issues whith my pixel art when moving (speed doesnt matter):
I'm moving in round pixel steps with my o_View (fiew centered arround that)
Code:
    if (instance_exists(o_Hero)){
        if !o_Hero.State_Menue{
            y += floor((o_Hero.y - y) * 0.3);
            x += floor((o_Hero.x - x) * 0.3);
        }
    }
Set up roomspeed from 30 to 60(currentrly) and it made everthing a bit smoother.
Resolution = system standard 1920x1080, base resolution for the game 640x360, also tried with doubble resolution, still the same tearing and flickering problems.
Having 2000-1000 fps, average 1070, while not recording.

Would actually prefer 30fps (=roomspeed 30?) if i can make everything make work properly on it.​
 
Last edited by a moderator:

Roderick

Member
1. Not directly. The instance being destroyed has to be the one to call instance_destroy(). In order to have an object destroy a different object, use
Code:
with (instance_id) {instance_destroy()}
If you're calling this from a collision event, you can use the keyword other instead of providing the id.

2- I'm not sure.

3- You use a different function, but I forget the function name. Someone will provide it, I'm sure.
 

FrostyCat

Redemption Seeker
1: with (inst) instance_destroy(); will do what you want. Though I would not recommend calling it instance_id --- it has another built-in meaning that always blindsides novices who don't read its Manual entry.

2: It works up to the object specified. instance_place(x, y, o_Parent) will account for everything whose inheritance hierarchy includes o_Parent.

3: instance_place() always returns one value, if more than one collision is found then it returns the instance ID from one of them. If you want to collect all of them, you have to go through a loop.
Code:
var inst, max_insts, colliding_instances, i, j;
j = 0;
max_insts = instance_number(obj_something);
for (i = 0; i < max_insts; i++) {
  inst = instance_find(obj_something, i);
  if (inst != id && place_meeting(x, y, inst)) {
    colliding_instances[j++] = inst;
  }
}
 
A

Aura

Guest
1. Use a with construction instead.

2. Using o_Parent would make GM take into consideration only the children objects of the same; parents and ancestors won't be taken into account.

3. There's no built-in function for that, but you can use scripts for that:

https://forum.yoyogames.com/index.php?threads/get-list-of-instances-in-region.7291/#post-52186

Note that the code I used returns the IDs of those instances that are found to be in a region, so you might have to alter it a bit (e.g. use instance_place() instead). If you're comfortable using lists, you can use these:

http://www.gmlscripts.com/script/Game_Play/Collisions/
 
V

vinceprinceking

Guest
You answered all my questions regarding 1-3, thx for the help. But here is a new one:

4. In the following code i try to see if some obj o_Parent_Usable or some of its Childs is on a certain position, afterwards i want to do specific if its o_Child1 o_Child2 o_Child3 and so on. Am i doing it right? code isnt working right now. any suggestions? Or do i have to check for postion_meeting for every child on its own?

Code:
if position_meeting(x+xx,y+yy,o_Parent_Usable){
       
        var ID_Of_Instance = instance_position(x+xx,y+yy,o_Parent_Usable);
       
        if object_get_name(ID_Of_Instance) == "o_Child" {
            scr_DoStuffwith(ID_Of_Instance)
}}
5. can i save a room-id in a varable so i can teleport back later?
6. can i toggle persistence of a room on and off with code?​
 
Last edited by a moderator:

TheouAegis

Member
Forget about the name of your objects. The object_get_name() functions are only really used for debugging.

First off, don't use position_meeting() and instance_position() in the same code. Use one or the other. Second, you can have your script handle all possible children. Just have it check argument0's object_index.

var n = instance_position(x+xx,y+yy,o_Parent_Usable);
if n scr_DoStuffWith(n);

If you don't like that and want separate scripts, then you can do

var n = instance_position(x+xx,y+yy,o_Parent_Usable);
if n switch n.object_index
{
case o_Child1: scr_DoStuffwith1(n); break;
case o_Child2: scr_DoStuffwith2(n); break;
case o_Child3: scr_DoStuffwith3(n); break;​
}


But at that point, you may as well just line all the scripts up (child scripting might work) and do

var n = instance_position(x+xx,y+yy,o_Parent_Usable);
if n script_execute(scr_DoStuffwith + (n.object_index - o_Child));

but most people don't like doing that because it takes a little more planning and foresight.


Question 5)
previous_room = room;
room_goto(target_room);

That would save the id of the room and go to a new room (as specified in the varible target_room). To get back to the previous room:

room_goto(previous_room);


Question 6)
Yes, but it won't work how you would want it to work. Maybe it works if you're already in the room, but usually you have to leave the room and then go back into it and then leave it again.
 
V

vinceprinceking

Guest
great thanks and here are the next questions:

7. so in the following code n returns true? so a Variable always returns true if its not -4, noone, 0 ??? Or is it just with Instance IDs? How exactly does that work?
[QUOTE="TheouAegis, post: 58913, member: 1973"
var n = instance_position(x+xx,y+yy,o_Parent_Usable);
if n scr_DoStuffWith(n);
[/QUOTE]

8. I know i can make a script return a boolean or a variable value. Can i make it return more than one? My solution would be to make a big string with ";" in between values, then make some script in a loop return values out of the string again. Is there a better solution?

9.Also what commands to get values back out of strings in general?

10. I got this Array right now where i store Item specific stuff like: "Name" (string), "Able_To_Pickup" (boolean), "MaxItemInPossesion" (int), "Able_To_Gift" (boolean)..., or if i had one for each specific NPC where all his "important" Values get stored. Where should i store Data like that, and Controller_Object, an .ini file, globals, and so on? I'm not talking about saving, just storing while the game runs. Are there rules when to use what and what is the most suited?

11. I have some screen tearing / flickering issues whith my pixel art when moving (speed doesnt matter):
I'm moving in round pixel steps with my o_View (fiew centered arround that)
Code:
    if (instance_exists(o_Hero)){
        if !o_Hero.State_Menue{
            y += floor((o_Hero.y - y) * 0.3);
            x += floor((o_Hero.x - x) * 0.3);
        }
    }
Set up roomspeed from 30 to 60(currentrly) and it made everthing a bit smoother.
Resolution = system standard 1920x1080, base resolution for the game 640x360, also tried with doubble resolution, still the same tearing and flickering problems.
Having 2000-1000 fps, average 1070, while not recording.

Would actually prefer 30fps (=roomspeed 30?) if i can make everything make work properly on it.








 

TheouAegis

Member
7) Anything greater than 0.5 will return true while anything less than that should return false (in Game Maker Studio, some versions only treated 0 as false, so if that happens, you need to upgrade). There is an issue with how booleans affect created variables, but that's a petty concern until it arises.

8) You can pass all the variables as a string, return the string, then extract each value from the string and use real() to turn each number back into a real number. Or you multiply each value (except the first) by the max value +1 of each value before it and add it with the previous value. For example, suppose you had A,B, and C where A could be a max value of 10, B could be 100, and C could be 255; you'd use the following formula:
return (A*100+B)*256 + C
Then to get the values back, just go in reverse using mod.
C = n mod 256;
n -= C;
B = n mod 100;
A = (n - B) / 100;

Or if you're comfortable enough working with bits, you can do the same thing a wee bit faster.


9) See first part of 8.


10) I'd prefer a controller object, or you go global. Reading from files is slower than reading from "instances" and a file will take up RAM as soon as you open it to read just like an instance.


11) My PC i am on right now sucks. Does the tearing actually show up in the video? I tried to watch and it was impossible for me to tell because my PC I'm on is crap.
 
V

vinceprinceking

Guest
for 11) Think i solved it at least partially.
Switching to "Full screen" fixed it but gave me one big tearing strip + "allow synchronization to avoid tearing solved" it. (at least as long as in full screen).

Here is a new one:
12) I draw on the GUI: draw_text(xx, yy, string(Time_Minute)). And in an alarm0 of the same obj i change that Time_Minute periodically. The Problem is it draws double (the old value and the new value) for a few frames.

13) Also can i make the GUI use the real resolution as base and adjust font-sizes and stretch images accordingly? for sharper menus and stuff?
Right now i use display_set_gui_size(640, 360) as 640x360 is my base resolution, but that gives pretty bad blurry texts.​
 
Top