GML Visual Create & Play

Hello all!

So I'm creating a game where I have most of the main bits in place now in terms of the theory set out, and the initial creation. However I am struggling on one part which is bothering me!

The initial concept of my game is you build your ship, fly it and see how far it goes. However the building is where I am struggling. You see I have got it so you can build your ship, but I need to be able to transfer what the player builds in one room, over to another where they can fly the ship.

I am using a grid method where the player clicks on a block, clicks the grid placement and it appears. Destroying the gridblock instance and replacing it with the built block.

Any assistance would be great and any questions/info needed I will get as soon as I can.

I really appreciate any and all help I get thank you!
 
A

anomalous

Guest
It sounds like you're basically there.
If you have a ds_grid that holds the block information, when you go to the new room, just loop through your grid and add all the proper blocks, and the ship is ready yes?
ensure that grid is in a persistent object, like your game controller or another appropriate control object.
 
I fear I may not have explained myself correctly. My grid is made up of objects as I am unsure how I would go about a ds_grid, apologies
 

NightFrost

Member
One of the simplest methods to move information between rooms is to declare a variable global. The content will persist through the game. A DS grid is a type of variable storage that works in the manner of a spreadsheet.
 
I don't mean to sound so stupid (which I totally am) but I can't get my head around how a DS grid will work in this situation?

Attached is my current room with placeholder graphics. So I have a grid, along with the parts on the right hand side. Clicking on these allows you to place it in the grid.
How would I use the DS_Grid method to lock a piece in to place? I understand using Globals etc but this grid is confusing me
 

Attachments

NightFrost

Member
Are those grid blocks created by a piece of code or have they been placed there in the room editor? To make your editor easier to expand, you should do that with code. If you haven't already, create an object called obj_editor_grid (or whatever is your preferred object naming method) and in its create event write two for-loops, one inside the other, and use create_instance() inside it to spawn the placeholders. That should be the first step to improve the editor.
 
A

anomalous

Guest
You don't necessarily need to use a grid. You can just write the data for each part to any list or array or whatever, and just read it back out.
Parent your object parts
Code:
offsetx = ?; // put whatever the upper left part's upper left coordinate is here
offsety = ?; // so if your first part is at 5, 5, put those there, and this will store the data
// at 0,0 as the upper left...just easier to remember they are all at position 0,0!

// to store the parts in a ds_list
list = ds_list_create();
with obj_part_parent// goes through every obj_part_parent that exists
    {

    ds_list_add(other.list, x-other.offsetx, y-other.offsety, object_index); // the order is the same as instance create below
    }
//to recreate the parts in that grid
var offsetx = 40;
var offsety = 40; // offset to place the objects, you can set to 0 or any number.
for (var i=0;i<ds_list_size(list);i+=3) // increment it by 3 each time since you have object name, x, y as inputs (3 inputs)
    {
    instance_create(list[| i+0]+offsetx, list[| i+1]+offsety, list[| i+2]);
    }
// be sure to destroy the list when the object is destroyed and/or when the room ends
 
Are those grid blocks created by a piece of code or have they been placed there in the room editor? To make your editor easier to expand, you should do that with code. If you haven't already, create an object called obj_editor_grid (or whatever is your preferred object naming method) and in its create event write two for-loops, one inside the other, and use create_instance() inside it to spawn the placeholders. That should be the first step to improve the editor.
I am using an object to create the grid as initially I thought this would be the best method to create the idea I wanted.

You don't necessarily need to use a grid. You can just write the data for each part to any list or array or whatever, and just read it back out.
Parent your object parts
I can't say I understand too much of this scripting as I've never really delved in to DS before.
 
Okay so initially it error-ed a few times whilst I figured out the code, and now it allows me to place one object, before giving me this:

Code:
Variable <unknown_object>.<unknown variable>(100003, -2147483648) not set before reading it.
 at gml_Object_Obj_Ship_Build_LeftButtonPressed_1 (line 19) -     ds_list_add(other.list, x-other.offsetx, y-other.offsety, object_index); // the order is the same as instance create below
Obj_Ship_Build is the name given to each of the squares to make up the grid.
 
A

anomalous

Guest
You need to put your code in some controller object, not in the obj_ship_build.
Also, if Obj_Ship_Build is the object you want to store and recreate to make the ship, then the "with" statement should be using that object.
See what you can do, put if not working post the code and I'll tweak it for you.
 
You need to put your code in some controller object, not in the obj_ship_build.
Also, if Obj_Ship_Build is the object you want to store and recreate to make the ship, then the "with" statement should be using that object.
See what you can do, put if not working post the code and I'll tweak it for you.
Sorry Obj_Ship_Build is the grid. I've probably gone about this some really long way, as each square is an object.
I really appreciate your patience and help with this!

There's multiple objects to be stored as there are different types of parts.

Also which type of event should this go in?
 
A

anomalous

Guest
I see you wanted D&D, sorry! if you really want D&D you can ignore me in favor if someone familiar with D&D commands.
 
Last edited by a moderator:
I see you wanted D&D, sorry! if you really want D&D you can ignore me in favor if someone familiar with D&D commands.
I can do coding with a little help! Drag and Drop is just easier for me! :p
I've never really gone this far in to coding so it's quite interesting trying to figure it out!
 
Top