GM:S 1.4 Please explain something to me experts/devs.

Discussion in 'Legacy GameMaker Community Tech Support' started by AncientPaul, Feb 7, 2019.

  1. AncientPaul

    AncientPaul Member

    Joined:
    Oct 26, 2016
    Posts:
    134
    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)
     
  2. Neptune

    Neptune Member

    Joined:
    Jun 21, 2016
    Posts:
    1,020
    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.
     
    AncientPaul likes this.
  3. AncientPaul

    AncientPaul Member

    Joined:
    Oct 26, 2016
    Posts:
    134
    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: Feb 7, 2019
    Neptune likes this.
  4. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,535
    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.
     
  5. AncientPaul

    AncientPaul Member

    Joined:
    Oct 26, 2016
    Posts:
    134
    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: Feb 7, 2019
  6. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    931
    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?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice