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

script works when its not a script but doesnt when it is a script

P

Philip Wee

Guest
Hey guys facing a pretty stupid problem, sorry im quite new to gamemaker

So my code works when it is in my step event:

but when i copied and pasted it into scr_create_prox_menu, and replaced all the obj_proximity_test with argument0 and all the prox_MENU with argument1, and put it back into my step event as the script it stopped working! ARGH

MAIN PROBLEM:

So after running it through the debugger, I realised that prox_MENU[0] was not being set to true when i swapped it out with argument0[0] = true and ran the script. Any idea how to fix that?

Code:
if (place_meeting(x,y,obj_proximity_test) = true && prox_MENU[0] = false)
{
    prox_MENU[0] = true
    for(i = 1; i < array_length_1d(prox_MENU); i += 1)
    {
        ds_list_add(EXPANDABLELIST,prox_MENU[i])   
    }
    
    for(i = 0; i < ds_list_size(EXPANDABLELIST); i += 1)
    {
        EXPANDABLEMENU[i] = ds_list_find_value(EXPANDABLELIST,i)   
    }
    scr_truncate_menu(EXPANDABLEMENU)
    show_debug_message(string(EXPANDABLEMENU))
}

if (place_meeting(x,y,obj_proximity_test) = false && prox_MENU[0] = true)
{
    prox_MENU[0] = false
    for(i = 1; i < array_length_1d(prox_MENU); i += 1)
    {
        ds_list_delete(EXPANDABLELIST,ds_list_find_index(EXPANDABLELIST,prox_MENU[i]))   
    }
    EXPANDABLEMENU = [];
    for(i = 0; i < ds_list_size(EXPANDABLELIST); i += 1)
    {
        EXPANDABLEMENU[i] = ds_list_find_value(EXPANDABLELIST,i)   
    }
    scr_truncate_menu(EXPANDABLEMENU)
    show_debug_message(string(EXPANDABLEMENU))
    show_debug_message("uncolided")
}

Script code:

Code:
if (place_meeting(x,y,argument0) = true && argument1[0] = false)
{
    argument1[0] = true
    for(i = 1; i < array_length_1d(argument1); i += 1)
    {
        ds_list_add(EXPANDABLELIST,argument1[i])   
    }
    
    for(i = 0; i < ds_list_size(EXPANDABLELIST); i += 1)
    {
        EXPANDABLEMENU[i] = ds_list_find_value(EXPANDABLELIST,i)   
    }
    scr_truncate_menu(EXPANDABLEMENU)
    show_debug_message(string(EXPANDABLEMENU))
}

if (place_meeting(x,y,argument0) = false && argument1[0] = true)
{
    argument1[0] = false
    for(i = 1; i < array_length_1d(argument1); i += 1)
    {
        ds_list_delete(EXPANDABLELIST,ds_list_find_index(EXPANDABLELIST,argument1[i]))   
    }
    EXPANDABLEMENU = [];
    for(i = 0; i < ds_list_size(EXPANDABLELIST); i += 1)
    {
        EXPANDABLEMENU[i] = ds_list_find_value(EXPANDABLELIST,i)   
    }
    scr_truncate_menu(EXPANDABLEMENU)
    show_debug_message(string(EXPANDABLEMENU))
    show_debug_message("uncolided")
}


(Also i know its kinda of stupid to make an array into a ds script and then make it into an array AGAIN but at least that i know how to fix)
 

Paskaler

Member
When you pass an array into a script and then do sometging like

argument[0] = value

The array is copied and from then on, in the script, you're going to be working with a copy. The way to fix this is to use an accessor, like this

argument[@0] = value

This will modify the contents of the array you passed in.

Be sure to read up accessors in the manual, too. There are ones for ds_lists and for ds_maps.
 
P

Philip Wee

Guest
When you pass an array into a script and then do sometging like

argument[0] = value

The array is copied and from then on, in the script, you're going to be working with a copy. The way to fix this is to use an accessor, like this

argument[@0] = value

This will modify the contents of the array you passed in.

Be sure to read up accessors in the manual, too. There are ones for ds_lists and for ds_maps.
THANK YOU SO MUCH THAT WAS SUCH A SIMPLE SOLUTION FOR SOMETHING I WAS STUCK AT FOR 2 HOURS GEEZ
 
Top