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

Add to ds list in script

JimPancakes

Member
The following code worked well when it was inside an instance but once I put it inside a script and called it from the same instance it does nothing.
GML:
/// @function destroy_line(amount, first, last, direction, list);

function destroy_line(_amount, _first, _last, _list)
{
    var _check_here = 0;
    
    while _check_here != _amount
    {
        var _check_list = ds_list_create();
        
        var _plank_nr = collision_line_list(_first.x, _first.y + (32 * _check_here), _last.x, _first.y + (32 * _check_here), all, false, true, _check_list, false);
        
        var _plank_first = ds_list_find_value(_check_list, 0);
        
        var _plank_sum = 1;
        
        for (var i = 1; i < _plank_nr; ++i)
        {
            var _obj_id = _check_list[| i];
            
            if object_get_name(_obj_id.object_index) = object_get_name(_plank_first.object_index)
            {
                _plank_sum += 1;
            }
        }
        
        _check_here += 1;
        
        if _plank_sum != 1 && _plank_sum = _plank_nr
        {
            
            ds_list_add(_list, _check_here);
        }
        
        ds_list_destroy(_check_list);
    }
}
Is there a reason why ds_list_add(_list, _check_here) wouldn't work when called from inside a script?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Is there a reason why ds_list_add(_list, _check_here) wouldn't work when called from inside a script?
Are you sure that's the actual issue? Run the code in debug mode with a breakpoint and step through the function a line at a time and make sure it's doing what you think it's doing and that all the values are correct...
 

JimPancakes

Member
Are you sure that's the actual issue? Run the code in debug mode with a breakpoint and step through the function a line at a time and make sure it's doing what you think it's doing and that all the values are correct...
Just so I have it clear in my head, the list that I supply should come out with the data that the script puts in it right? There's no "return" or whatever that needs to be there in order for it to work?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Correct. in tis case the list ID you input should be the list that gets modified by the function with no need for a return.
 
Top