• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Legacy GM Please explain something to me experts/devs.

G

Guest User

Guest
Hello,
I've been working on a game in gms 1.4 for some time now and although it's mostly going well (with help from friends) I came across a problem recently that I would like to understand but I just don't.

I'll try and keep it short, but in my game I have a mini-game puzzle and that is what I've been working on recently and once it was fully tested and worked perfect (as far as I could see), I then had like 15 sprites and 20 objs named spr_puzzle_x, obj_puzzle_x

as you can imagine the sprite/object list at the side was very messy so I created a folder called 'puzzle' to put all my puzzle obj's into.. this immediately caused my game to stop working correctly and the puzzle was broken.

I loaded a backup and it was fine. made a folder, added the objs and again.. suddenly the game isn't working right.

it seems that because I changed the order of the objects when dragging them into the folder, that is what broke my game. but after much searching and googling, I cannot understand why the position of an obj in the asset list would mess something up?

Could some kind person please explain (very simply,as I'm stupid) how moving an obj into another place on the list can break the game?

(I'm sure if I understand why it's doing this, then I'll be more careful in the future)
 

Neptune

Member
You're not stupid, and its probably just a simple mistake.
Resources in your asset tree are given a number index, 0 1 2 3 4 5 etc, and that index is used in your code, for example
Code:
if obj_puzzle == 3 {/* this may be true...*/}
So i'm assuming you're storing/saving a resource tree index (never encouraged because of this problem), and then once you shuffle your tree around, your save data is all messed up -- 3 now points to obj_rock and and not obj_puzzle...

It would be nice if GM would just allow you to toggle whether or not these values change when you move your resources around, but... for now thats the way it is.
 
G

Guest User

Guest
Ahhhh!!

There is one place in my puzzle that uses asset_get_index! That could be it.

is there a way to 'reset' the tree index?
 
Last edited by a moderator:

TsukaYuriko

☄️
Forum Staff
Moderator
Resource IDs should be rebuilt on every compile.

Execution order depends partially on object IDs, so chances are that you messed up the execution order by moving the objects around in the resource tree. The underlying cause of this would be that there's something in your code which relies on the ID-sorted execution order - that's what should be examined.

It could be something as simple as object B requiring an instance of object A to exist when running code in its Create event (and not checking whether an instance exists first), which works just fine as long as instances A execute their code first. Changing the execution order so that instances B execute their code first will result in a crash.

A less crashy example could be two moving instances, both moving to the right, but only if there's not another instance to their right already. Assuming that both instances are placed next to each other with no gaps, if the rightmost instance comes first in the execution order, the two instances will move as if they were one. If the leftmost instance executes first, there will be a small gap between them as, while it can not move on the first step due to the rightmost instance blocking it, the rightmost one can and will move. Applied to a large scale, this can cause all sorts of unwanted behavior.

A common solution for this is to decentralize the problematic code and instead let a third party handle execution (object A and object B need to execute in a specific order -> introduce object C, which manages the execution for them). This way, you can guarantee that any such code will always execute in the order you want it to execute in.
 
G

Guest User

Guest
Thanks for your help, I do appreciate it, although I didn't understand most of what you said. especailly the last part. I'm just really dumb. sorry


Edit: thanks again for the help, I've totally rewritten the code and left out any asset_get_index commands. sure the code is 150% more ugly and 400% longer but it works so I don't care. ;)
 
Last edited by a moderator:

chamaeleon

Member
Thanks for your help, I do appreciate it, although I didn't understand most of what you said. especailly the last part. I'm just really dumb. sorry


Edit: thanks again for the help, I've totally rewritten the code and left out any asset_get_index commands. sure the code is 150% more ugly and 400% longer but it works so I don't care. ;)
Using asset_get_index() should be fine. It surely must return the index for the provided asset or an awful lot of code would break for many people. Was the bug manifesting itself because you made assumptions about "intermediate" assets by assuming you can use ranges of asset ids between two asset_get_index() values, perhaps?
 
Top