• 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!

miscrosoft excel-like coding

R

rjenman

Guest
Hi

I'm wondering if there is any way to do microsoft excel-like coding
for example:

a chunk of code referring to object obj_001... then 997 more identical chunks of code for obj_002 to obj_999.... in excel you would do for example set cell A1 = 001 and set B1 = A1+1 and then click and drag the code across 999 cells total.

My biggest problem is that i could code the numbers 001 to 999 but i don't know how to make it appear with "obj_" in front of it every time without it disrupting the code

there's just so many times i find myself tapping "down" 5 times and then manually adding 1 to a number, like 20 times.
 
Not sure what you are trying to do, there may be better options like making an array of objects, but if you want to do it your way:

Code:
for (var i = 1; i < 1000; ++i)
{
    var my_object = asset_get_index("obj_" + string (i))
}
If you want the leading zeros you might need to add a bit of extra strings in there, or string_format() function might also do the trick.
 

Simon Gust

Member
I don't know how to feel about creating 1000+ objects. I think you should definetly work with instance arrays / grids / maps here.
 

TheouAegis

Member
Or, you know, write your code in Excel and then copy paste it into GM. LOL Not as clean and easy as arrays, but its faster than copy-paste-edit within GM.
 
R

rjenman

Guest
Or, you know, write your code in Excel and then copy paste it into GM. LOL Not as clean and easy as arrays, but its faster than copy-paste-edit within GM.
dude u know that may actually be a brilliant idea
 
R

rjenman

Guest
I don't know how to feel about creating 1000+ objects. I think you should definetly work with instance arrays / grids / maps here.
i was more thinking of a big long document of really similar codes but for different objects, all named the same with a different number in the name

that said i dont even know what an array/grid/map is so i'll look into that
 

TheouAegis

Member
dude u know that may actually be a brilliant idea
I did it once. With how forgiving GM is about spacing and punctuation, I wrote one part in one cell, a formula in another cell, another tied-in formula in another cell, then dragged the contents down, selected all, copied, then pasted into GM.
 

NightFrost

Member
I did it once. With how forgiving GM is about spacing and punctuation, I wrote one part in one cell, a formula in another cell, another tied-in formula in another cell, then dragged the contents down, selected all, copied, then pasted into GM.
I've done this too. I needed a list of five hundred values calculated according to a formula. Since they were prices for an idle clicker they went over the highest number GMS could understand, so I needed them as strings that I could then split into arrays. I put the necessary stuff into two columns in excel, dragged down to row 500, copied to a basic text editor where I cleaned it up a little, then pasted into game init object.
 

Jezla

Member
If I'm understanding right, it sounds like what you want is to create a parent object with the code. In this parent, create an array or data structure that adds each new instance to it.

Then you can just refer to the instances by their position in the array or data relative to other positions, without needing to hard code every specific object index or instance id being used. I'm not at my computer at the moment, but I can post an example when I get back to it, if you like.
 

GMWolf

aka fel666
There should basically never be a case where you have to copy code in a project.
Learn about scripts, arrays, data structures and parenting.
The manual has great entries on each of those to get you started.
 

Dr. Wolf

Member
There's bound to be a better way of doing what you want than what you have planned...

That said, keep in mind that object indices are just numbers, and are in order based on their position in the resource list. Thus, assuming you have arranged the objects in order in your project's resource list, you could iterate through them with a "for" loop:
Code:
for (var i = obj_001; i <= obj_999; i++)
{
     //Do something!
};
Seriously though, don't do this ^. Learn about data structures, arrays, parenting, scripts, and GML in general, and then find a more sane way of accomplishing what you want.
 
Top