A Few Questions About Objects As Variables/Structures

Hi, I’ve just started using GDevelop and have run through the cannon tutorial. I’ve made a couple of small games in Stencyl before but now I want to work on a larger project and I just don’t think Stencyl will be able to handle it so I thought I’d switch to GDevelop. So far I really like the structure (although it takes a bit of getting used to coming from something as simple as Stencyl) and the way you can quickly throw events together.

The game I’m planning is going to be a top-down space combat game, a similar to Elite (more like AsciiSector actually) but with less focus on trade and more on pirate hunting and performing missions.

Because it’s potentially going to very complex (ships stats and equipment, procedurally generating NPC ships in a sector when the player arrives and pathing them all, etc,) I’m trying to plan out as much of the structure as I can before I start hacking away. This has thrown up a few questions that I need to answer before I go too far down what may be a dead-end path.

So firstly, thinking about the player’s ship, I’ve started building some ship sprites in Inkscape and I’ve deliberately left them with empty weapon mounts rather than include them with each ship (more on that in a bit). Once I’ve got a sprite/animation for every player ship in the game I plan on adding them as objects and giving each one a bunch of variables (possibly as a Structure) to determine their base stats (hit points, turning speed, number of weapon/engine/shield mounts, ect).
So far so good. The question then is how do I tell the game which ship the player owns. I think I can do this with a global variable (another structure) which will hold all the details for the player (cash, ship owned, any systems on the ship, cargo, faction respect/hostility levels, etc). The question is, can I simply use the Ship_Type global variable to store the name of the particular object and use that to spawn it at the start of a scene (i.e. when a player jumps into a new sector or launches from a planet/station)? That seems the simplest idea to me but I’m not sure if GDevelop can interpret a text string in a variable and apply it to an object in that way.

Assuming it can, then it would follow that I can also create all the different ship systems as further objects (although any internal systems won’t have sprites associated with them) and refer to those from the same global variable/structure to generate the entire ship loadout when the scene is created.
This throws up another question, which is how do I deal with the differences between larger and smaller hulls. If, for instance, the starting ship has two gun hardpoints I could have Hardpoint01 and Hardpoint02 as child variables and populate them with specific weapon objects (say, “20WM_laser” and “missile_launcher”). But what happens when they buy a new ship with 3 hardpoints? Can I dynamically add/remove child variables from the global structure or should I build the initial structure to include the maximum number of possible child variables and then some force each individual ship to limit how many they can use?

And, final question (for now): My current plan is to represent interchangable weapons on the ship sprites themselves. This not only looks better but, in theory, allows me to create each weapon object with a sprite and a standardised event that holds all the actions for it firing while the specific numbers used for each variable (damage, range, rate of fire and which projectile object to spawn) can be held in the weapon’s own structure variable which seems like a good way to handle it. I also like the fact that I can define particular points on the ship sprite and my plan is to designate those as hardpoints and then, when the ship is generated upon entering the scene, spawn the appropriate weapon sprites and attach them to the hardpoints. The only question is I’m not at all sure that is possible under GDevelop. They problems I can think of are forcing the Z-order correctly (some ships may have mounts on the underside with only a small part of the weapon visible from the top-down perspective) and that while I may be able to spawn the weapons at the correct point, they may drift off by themselves when the ship starts moving so I need to know if there’s a way to “stick” them to the ship. Under Stencyl I would have used the weld joint from the joints extension but I’m not sure what the equivalent is for GDevelop. I probably need to make my way through some more tutorials but I’d like to get some answers so I know if all this is going to run into serious technical limitations before I even start. If so I can probably rethink how to do it.

Any help or advice will be greatly appreciated and I’ll probably have some follow-up questions depending on the answers to these.

You can use the content of a text variable as an object’s name only for the object creation action (to spawn the object on the scene). Then, if you want to manipulate that object, you’ll have to refer to it through an object’s group (in which you can put all the possible objects that can be spawned at this place: for example, a group for the weapons, another group for the engines…)

Thanks for your response. I’ve had a look at the documentation for object groups but there’s not much there. Does your post mean that I’ll only be able to refer to an entire group of objects rather than a specific object?

I think that could cause problems when buying or selling ship systems. If the shipyard scene has a list of items it sells, it seems to make sense to be able to pull the stats and price for any of those objects by looking at a variable inside the object itself, but that won’t be possible if I can only refer to all objects within a specific group.

Or am I reading your reply wrong?

Again, thanks for your help with this.

Depends on the actual game design but you can use object variable to simply mark the actual ship object as “owned by player” or you can use it to store the actual name or ID of the ship object but you can also use the link object extension to link the actual object to the player.

Yes, it is totally possible. What you need to do is store all the ship objects in a group that potentially can be owned by the player and simply, store the name of the ship currently used, owned by the player in a variable and at the beginning of each scene (sector, system) just create the ship object from it name for the player.
As of stats like fire power, fittings…etc you can store/save them in a file on native platform or in web storage in HTML5 and read the info when the ship object is created.

You can dynamically add and remove structures from variables, but the latest version of GDevelop introduced a new inventory system that might make it easier to store things like this. This topic can be really complex so I can’t give you an explanation of “How” right now but in case you want to customize ships with different fittings and upgrades similar to EVE Online, it is possible…

I’m not sure if I understand but in case you mean you want to store fire power, rate, speed…etc for each weapon individually using object variables, it is possible.

In GDevelop there is no parenting or pining option to pin/join objects but If you want to do it only on the player ship, it no problem, you can set the Z order of the objects and also the position of any object to be at the specific point of the player ship. To make sure the objects are not drifting away, you need to update the position every single frame.
In case you want to do this with multiple ships in the game also AI ships, it is going to be more complicated especially if you are creating ships and their fittings dynamically on the fly. First you need to create a link between the objects using the object linking extension and then need to go through every single instance of every single object, find which instance is linked to which object and move them in to position every single frame. Personally, I would do this only for the ship controlled by the player.

@ddabrahim:Awesome! Thanks for that, chap. That all sounds as though I should be able to do what I’ve got mind (or at least it should be possible from a technical standpoint).

I totally agree about only using interchangeable weapons for the player and I’d already decided to use pregenerated NPC ships with fixed loadouts to keep down the processor overhead on dealing with them.

Thanks again! I’ll start looking at throwing together some test stuff now.

Cheers.