1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Create New instance, check all other of same instance, combine into new instance

Discussion in 'Programming' started by Johnathan, Mar 8, 2018.

  1. Johnathan

    Johnathan Guest

    I have been fighting this for days now and its time I find some help...
    there are 10 stores.
    It falls into a inventory kind of thing. Basically, you pick the store (global.store) the item (global.item) rather its going in or out, (global.in_out) and quantity (global.qty1).
    After you pick all these it creates an instance (object_pos_transfers) that stores all of this into local variables.

    What I need it to do after that is when a new instance of object_pos_transfers, is check ALL other instances of pos_transfers and combine them if they have the same local variables.

    they are persistent if that matters as they go through multiple rooms

    i can get the first store mooresville to combine the items to the new object of mooresville. but once i do any other store it doesn't combine and also mooresville no longer combines. I understand that the collision circle is only returning 1 instance. I tried to cycle trough a temporary ds_list with all the instances of object_pos_transfers but I can't get it to work.

    collID = collision_circle(x,y,2000,object_pos_transfer,false,true)

    if( collID ) {
    if( canCreate ) {
    canCreate = false;

    collID.canCreate = false;
    if month = collID.month{
    if day = collID.day{
    if year = collID.year{
    if this_store = collID.this_store{
    if in_out = collID.in_out
    {
    with( instance_create( x, y, object_pos_transfer ) )
    {
    mooresville_transfers = other.mooresville_transfers

    if this_store = "Mooresville#(4223)"
    {
    for(var i=0; i<ds_list_size(mooresville_transfers); i++)
    {
    if ds_list_find_value(mooresville_transfers,i) = global.item
    {
    inv = false
    }
    }
    }
    if inv = true
    {
    ds_list_add(mooresville_transfers,global.item)
    }
    with (other)
    {
    instance_destroy()
    }
    with (other.collID)
    {
    instance_destroy()
    }

    }
    }
    }
    }}}}
    }

    else{
    canCreate = true;
    }
     
    Last edited by a moderator: Mar 8, 2018
  2. Spencer S

    Spencer S Member

    Joined:
    Aug 4, 2017
    Posts:
    125
    I'm not sure I quite understand the problem. It sounds like you're trying to compare values from a bunch of objects. What you could do is create a new ds_list for each object that holds all of those variables. I know you said you tried doing that already, but a ds_list sounds like the perfect solution to your problem. Create new ds_lists for each object_pos_transfers, then run a for loop that compares all of those ds_lists (or whatever specific ds_lists you need). If anything is == , execute the next lines of code.

    Sorry if this didn't help, but there's just too little info for me to go on right now.
     
  3. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,973
    I'm also not really sure what you're going for. It seems like it would be better to have a persistent object that just holds the information in an array or list that checks against itself and if you needed an object on screen for collision purposes or something that object just pulls from the array (much like a generalized inventory system), but working within your idea you would probably want the following:
    • When an instance of the transfer object is created, it goes through every other object of it's type
    • It checks for a variable which serves as a trigger to merge
    • When it fines that variable it loops through any important variables and copies them
    • Then destroys that object.
    For example assuming a known number of stores and items:

    Code:
    
    enum store_name {
         //list all store names
    }
    
    enum item_name {
         //list all items
         height, //make this the last one
    }
    
    //create event of store
    name_of_store = store_name.store_1;
    
    store_inventory[item_name.example_1] = 5;
    store_inventory[item_name.example_2] = 5;
    store_inventory[item_name.example_3] = 0;
    
    checked = false;
    
    //in step event of store or wherever you want it to run
    if (checked == false) {
        with (obj_store) {
            if (id != other.id) {
               if (name_of_store == other.name_of_store) {
                    for (var i = 0; i < item_name.height; i += 1) {
                        other.store_inventory[i] += store_inventory[i];
                    }
                    checked = true;
                    instance_destroy();
                }
            }
        }
    }
    
    
     

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