Following tutorial - Translating from old scripts to new

S

Sojourner

Guest
To preface this, I'm quite new with coding entirely and will probably be clunky in explaining my issue.

I've been following FriendlyCosmonaut's tutorial for a Farming RPG. It was created in 2017, before the 2.3 Script Update. I've been having issues with my coding (specifically, making the crops persistent after leaving the room), and after rewatching and checking my code, the only thing that's different is the script (and rightfully so, they were changed). I checked the manual explaining the update, and it didn't quite click in my brain.

Here is the way it was written in the video (before version 2.3)

/// @desc respawn_crop
/// @arg grid_x
/// @arg grid_y
/// @arg crop_type
/// @arg days_old

cellSize = 32;
var xx = argument0*cellSize;
var yy = argument1*cellSize;

// Create the Instance
var inst = instance_create_layer(xx+(cellSize/2), yy+(cellSize/2), "Instances", obj_crop);
ds_crops_instances[# argument0, argument1] = inst;
show_debug_message("Respawned a " + ds_crops_types[# 2, argument2]);

// Give the crop correct characteristics
with(inst){
cropType = argument2;
daysOld = argument3;
growthStageDuration = crops.ds_crops_types[# 0, cropType];

}

return inst;



How would this look in the new update?
 

FrostyCat

Redemption Seeker
GML:
///@func respawn_crop(grid_x, grid_y, crop_type, days_old)
///@arg grid_x
///@arg grid_y
///@arg crop_type
///@arg days_old
function respawn_crop(grid_x, grid_y, crop_type, days_old) {
    cellSize = 32;
    var xx = grid_x*cellSize;
    var yy = grid_y*cellSize;

    // Create the Instance
    var inst = instance_create_layer(xx+(cellSize/2), yy+(cellSize/2), "Instances", obj_crop);
    ds_crops_instances[# grid_x, grid_y] = inst;
    show_debug_message("Respawned a " + ds_crops_types[# 2, crop_type]);

    // Give the crop correct characteristics
    with(inst){
        cropType = crop_type;
        daysOld = days_old;
        growthStageDuration = crops.ds_crops_types[# 0, cropType];
    }
    return inst;
}
 
Top