News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

I have some questions about arrays

Started by TobiMikami, December 02, 2022, 03:41:39 AM

Previous topic - Next topic

TobiMikami

Hey guys so if you're familiar with my Prime 2D engine and fame "The Tallon IV Project" you know I'm using Game Maker Studio/GML, I know GML is very similar to C++ as I did do some reading on C++ before I even started hacking SM before I did free code fangames. I've learned everything I know about programming by reverse engineering SM, Kousoru and now Physixs GML engines, and watching tutorials and reading stuff. Working with the more complex engines, I've come to discover array functions and they're a little more finicky I noticed than standard variables.

For example, a major issue right now is an array with the map, it obviously works fine in MEngine, the map_init script runs fine, which reads all the map data from the file his map maker creates. I opened the existing map file for MEngine to find how to name the room, put the camera in, even though it's redundant ATM, hatches, everything. But I still end up with an issue with an array somehow. I should note specifically, this is. '2D array' I believe is what it's referred to as?

So far, I understand arrays are a list function, I've used some 1D arrays, for example local var Artifacts[0]/[11] (I presume that local vars eat less vram than global vars? If someone could confirm or deny that'd be awesome lol) However because the map has two coordinates it converts between a Data structure grid and an array, with the array function being like MapGrid[x,y] and each variable is a separate variable defined elsewhere, one being "currentWorld" which is implied think the one throwing the error. It's like "MapGrid[CurrentRoom, Current(whatever it is)] and the fatal error is that this variable is undefined, so I logically said okay for some reason, it isn't reading this variable, so I tried defining it trial and error as usual, set it at zero, it said "Array must be +ive" I figured that meant positive? So I changed to one, got the same thing. I know I also read arrays are supposed to be "addative" or something. Like they're supposed to go 1,3, 5, 10, 20" but if you go 1,3,2,4" that would screw it up apparently? I believe that was fixed with the naming of the room, but then it was another variable in the same area, and the error was "attempting to index a variable that is not an array" and well quite frankly for once in my life one of the rare few times, I'm stumped and have been for days, spend literal days a week ago trying to make this map work before I gave up to work on better things, I tried to do some research as I tried to demonstrate here to reinforce my own knowledge and ask questions so others who may have insight can clarify what I may be missing or misunderstanding, I know it's up to me to fix my own code, nobody has an answer to that, but I've checked every single object, script, and function I could think that would relate to that map.

I'd like to be able to utilize arrays more as I write my own codes as I know they're versatile but because I'm using Kousorus global var systems and Physix's engine saves the arrays, I can set if global.MB = 1 {Power[0]=1} to equal the Morph ball var to the array, but if I try to load the save file and retrieve the variables the opposite way and say if Power[0]{glbal.MB=1} I get a fatal error. I'd like to know WHY that is, what the proper formation of the array then is, otherwise I'll have to rewrite those parts of code to the arrays instead.

One main, main point though is, with the 2d array especially for the map, is +Ive supposed to mean "positive" or "additive?" For two, how does it return "trying to index a variable that's not an array" when it is in fact an array, as the variable should be read as its value not as the word (and since it works in the original, I know the function should work, I know it's gotta be some tiny miniscule little thing on my part I'm missing.) All I can do is try and troubleshoot by learning how these things interact and everything. I know there's a few who do GM specifically, but we got a wide variety of programming types from HEX, ASM, Python, and C++, since the questions are yeah related to GML, but are more programming logic related , I'm hoping someone with more code experience can understand somewhat of what's up with the info I'm able to provide. Thanks In advance, it helps bring us a step closer to the reality of a (full) Prime 2D! c:

VacantShade

Its very hard to know what the issue is without viewing a large portion of the code. ^^"

For questions about specific things like this, I'd recommend joining the Game Maker Discord:
https://discord.com/invite/gamemaker

For learning GM fundamentals like arrays and many other features, I recommend this youtube channel: https://www.youtube.com/@SamSpadeGameDev

Along with that, if you plan on this being a major project with a substantial development time, I'd really recommend moving to the latest version of Game Maker. It has so many more features and benefits for streamlining your development.
It's free to develop on, and the subscription to build for Windows is only a few dollars, which you can get for a single month if you want.

I'd also recommend moving away from existing engines others have made, since it can lead to this exact issue, where it can be hard to understand how their code works and what it could interfere with. It takes a lot of work to make an engine from scratch, but the learning experience is worth it in the long run in my personal opinion.  :wink:

Hope the project goes well, and remember to have fun!

TobiMikami

I actually ported up to 1.4 somewhat recently because that was a whole other world of resources. I'm just starting to realize the full power of GMS1, if I go to 2, it won't be till after I finish a 1.1 release. I'd probably start building a new Zelda engine from scratch to do that learning because my Metroid engine is basically complete, it's got everything from Prime and SM, except grapple don't work fully yet.

Do you think you could answer me one very Simple generalized question though; does it take more memory to use a global var versus a local one? My engine I used globals but Physix used a lot of local array variables. Would I be better off to convert them to locals and just reference it as objControl.Var instead of global.Var?

VacantShade

It's more about scope than memory. Memory should not be an issue based on your project concept.
This video on the channel I linked explains it well.
https://www.youtube.com/watch?v=9TUpOHMtBzQ&list=PLwgH1hDD0q1Eq2xXKhkiJmtt7ml599CSt&index=6&ab_channel=SamSpadeGameDev