Converting a "name" to a real, then convert it back to a string - game-maker

I've ran into some issues with my current gamemaker project. I've setup a simple "merge" functionality in my game, and I'm trying to increase it's QoL
So what's happening when I'm merging, is this;
var sabatons = instance_place(x, y, object_index);
if (instance_exists(sabatons)) {
instance_create_layer(sabatons.lastknownPosX, sabatons.lastknownPosY, "Instances", "");
if (level >= 3) {
scr_spawn_experience();
}
audio_play_sound(snd_sabatons_merge,10,false);
instance_destroy();
instance_destroy(sabatons);
}
So what the code above does, is to check if object_index matches with what I'm trying to merge it with, and if it does, it runs instance_create_layer - which is where my question comes in.
My objects are easily named with a digit at the end, to keep track of their "level"
so basically, obj_sabatons_1 means it's the first item in a chain, obj_sabatons_2 is the second etc. Now what I need help with is to convert whatever the object is that I'm trying to merge with, to a string (object_index) but increase it with 1, so I then can put that result in my instance_create_layer so the game will create the next level of item, if I successfully merge my first two items :)
Thanks!!

Is there a reason that the level should be part of the name? If not, then you could convert the level into a variable of the object obj_sabatons, so you can keep all the code related to obj_sabatons in one place (And then remove all those copied objects with digits at the end)
Making multiple copies of the same object can be disadvantageous in numerous ways, For example, if you want to expand the limit, then you'd have to create a new object for each level, making a code change also means changing that code in every other object level (unless you're making use of parents/child objects), it would also make the progress of merging objects into new objects easier

Related

How do I create a random item spawner with no repeats?

I am currently working on a rogue-like game in GameMaker Studio 2 and i would like to have an item spawner where no items are repeated.
I have tried multiple different ideas of what i think would work, such as giving items and id variable and only spawning items which hasn't had it's id called, although it doesn't seem to work.
The code I have right now is basic, but that is because it's the only way I've been able to spawn an item, there is repeating items with what i have and i would like to stop that from happening.
Here is the Create code of the object:
// Items
var items = choose(
obj_homing,
obj_tracking,
obj_bounce,
obj_double_xp,
obj_shotgun,
obj_orbit,
obj_firefaster,
obj_scattershot,
obj_damageboost,
obj_explosive
);
instance_create_layer(x, y, "Items", choose(items));
I haven't had any actually crashes in the game, although the errors i have faced are multiple of the same object spawning twice when i would like items to not repeat.
One option is to modify the items array after each call to remove the spawned item, and re-initialize it as full only at the start of each game or when the array is empty.
The problem I'm seeing in looking through the Game Maker Language Documentation is that I cannot find a way to delete an object from an existing array and resize the array.
You're placing choose on both defining the var, and when creating the layer.
Now, I don't know exactly what choose does, but I assume it's choosing randomly a selection from the array.
So Items would only return a single chosen item from the array, maybe it's better to remove the choose function from the Items, and only decide that when creating the object.
So the Items should become an array:
var items = [
obj_homing,
obj_tracking,
obj_bounce,
obj_double_xp,
obj_shotgun,
obj_orbit,
obj_firefaster,
obj_scattershot,
obj_damageboost,
obj_explosive
];
Just save the random instance in a variable, then when you create a random instance, check if equals to the instance that you have created previously, and if it is, call again the function until the previous instance is different from the new generated instance.
If you want to spawn every item only once, how about changing the current spawned object in the array to "noone".
And at every spawn cycle, you would check, if the selected item is noone and if so, select the next item (array[i++]).
Also do not forget to randomize the seed, somewhere in the beginning of your game with randomize().

How to get a range of columns as collection?

EDIT: For context, I am trying to import a certain range of columns in an Excel sheet into a Blue Prism object as a collection.
So I've got a worksheet with columns from A to AM. When I get sheet as collection, blank columns named "Column1" to "Column10" (the first time) and "Column1" to "Column19" (the second time, note its 19 cols this time) mysteriously appear in the collection. No data is in these columns - no whitespace, nothing.
In order to prevent anything of the sort from messing up the collection cols, I'm looking for a way to get a range of columns as a collection, e.g. A - AM. The number of rows is undetermined, so the get range as collection action is not suitable. Thanks in advance!
I never really liked the default object to get range as collection because of that. You can create a new action in the Excel VBO object (do make sure to be careful with that since re-importing the default object will basically erase the action. I usually rename it as 'MS Excel VBO Customized' or something along those lines).
The way I would do it is as follows:
Open the 'MS Excel VBO' object and duplicate the page 'Get Worksheet Rage as Collection' and name it 'Get Worksheet Range as Collection New' (or anything you deem suitable):
Edit the code stage: give it a new name (because code stages cannot have the same name in the same object) and change the inputs and code stages to match the following (I'm calling the new range as 'Address' here, but feel free to name it something else as long as you are consistent throughout):
Edit the start stage. You can delete the previous data items for Start Cell and End Cell and create one for Address:
Publish and save the object. You can then use it from the object or process you are working on and use a range such as A:AM.

Game Maker Studio Score, My Score resets when going to the next room

I'm having a problem regarding the scores in my game, My game is about answering questions using jumbled letters and when the player gets one correct answer, the game should add +1 to the game score and move to the next level (which is in the next room) and will generate another question, and keeping your last score which is 1. My problem is, the score just keeps on resetting to a value of 0 when moved into the next room. I want it to continuously add +1 even when I go to the next rooms. Thankyou in advance.
There are many solutions.
1) Set your score controller object as persistent
This is the best, as you don't need to do anything else, and in fact, it's a good rule to have one object as a persistent controller.
2) You can save your score to the file and load it each time this object (that stores the variable) is being created
This requires save\load manipulation, and in some cases (e.g you don't want to have ANY persistent objects) can be better, but I highly doubt.
You are not giving enough details about how are you storing the score value.
That may be cause by many issue in the way you are making the game, so im going to try to give all solutions to all possible scenarios:
1) Storing Score in Object Variable
This way may have two different sub scenarios:
a) Going to Next Room after Right answer
b) Restart the same room
This completly reset the variable on the object because the object is destroyed and then created again initilizing again the variables it hold when the room is created.
For this the solution is simply: set persistent true, you can do it from the form object properties (the interface that pop up when you open a object) or using gml on the create event of the object:
object: CREATE event
persistent = true;
This will make the object even if is repeated on the room created to no to create it again, so the event CREATE will no be never repeated again.
2) Storing the Score in variable of the room using Room Creation Event
In this scenario happeng the same that above, its just a local variable the room but exists only for the room and will only exists during the room until its restarted or leaved.
In this case the best is to transform this variable to a global instance in the following way:
global.points = 0;
And this is the best way to store score for you game.
Just remember no to put it in a create event of a not persistent object or it will be reseted to ZERO everything that object is created.
In that case you can check if the variable exists and then if not initializing it:
if (variable_global_exists("points") == true) {
global.points = 0;
}
Now if you want to save it you need to use file functions which is another question.

Stop diagonal lines to display after extracting powerclip contents

There was one time when I have a project that need duplication of objects in CorelDraw in order to save time. That moment then, I accidentally powerclipped an object inside an object that is to be duplicated for future use of other objects that needs same dimensions as the object I'm working now. As a result I extracted its objects and what happened is that, yes the objects got extracted but the container object have had diagonal lines from its objects. What can I do to stop or rather not come up again with a situation like this?
There are two ways:
1) Right click object, select Frame Type - None
2) Layout menu > enable Layout Toolbar. third button is remove frame
Unfortunately it is not possible to do such an operation on more than one object at the same time.

AdvancedDataGrid (grouping) quick jump to row

I have a problem with the AdvancedDataGrid widget. When the dataProvider is an ArrayCollection (of arrays), the nth array (within the collection) is also the nth row within the grid, and I can jump and display the i-th row by scripting
adg.selectedIndex = i;
adg.scrollToIndex(i);
now, when I add a Grouping, the dataProvider ends up being a GroupingCollection2, and now the index in the dataprovider's source does not correspond to the index in the adg anymore (which is understandable, because it's being grouped).
How can I select and display a row in grouped data efficiently? Currently, I have to traverse the adg and compare each found item with its data attributes in order to find the correct index of the row within the adg, and jump to it like above. This process is very slow. Any thoughts?
edited later:
We already used a caching object as Shaun suggests, but it still didn't compensate for the search times. In order to fully construct a sorting of a list of things (which this problem equates to, as the list is completely reordered by the grouping), you always have to know the entire set. In the end we didn't solve that problem. The project is over now. I will accept Shaun's answer if no one knows a better way in three days.
Depending on what values your comparing against you can store the objects in a dictionary with the lookup using the property/properties that would be searched for, this way you have a constant time look-up for the object (no need to look at every single item). Say for example your using a property called id on an object then you can create an AS object like
var idLookup:Object = {};
for(myObject in objects)
idLookup[myObject.id] = myObject;
//Say you want multiple properties
//idLookup[myObject.id]={};
//idLookup[myObject.id][myObject.otherProp] = myObject;
now say the user types in an id you go into the idLookup object at that id property and retrieve the object:
var myObject:Object = idLookup[userInput.text];
myAdg.expandItem(myObject, true);
now when you want to get an object by id you can just do
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGrid.html#expandItem()
I haven't done any thorough testing of this directly, but use a similar concept for doing quick look-ups for advanced filtering. Let me know if this helps at all or is going in the wrong direction. Also if you could clarify a bit more in terms of what types/number of values you need to lookup and if there's the possibility for multiple matches etc. I may be able to provide a better answer.
Good luck,
Shaun

Resources