I'm creating a storage system which allows users to join a group and share a storage between them.
When a group is created, it is assigned an ID. When a player joins the group, they are associated with the group with a permanent account variable.
If Alice is in group 0 and she deposits some items 50 items with ID 10 and 7 items with ID 21, the array `$global_storage_keys:0` should be set to `[10, 21]` and the variable `$global_storage:0:10` and `$global_storage:0:21` should be set to 50 and 7 respectively. However, when I try to update the keys variable with `setd`, only the first value of the array is preserved. How do I manipulate an array which I need to `setd` to access? Thanks.
function script add_id_to_global_store {// Adds the ID an an item to the key store.// arg0: the integer ID of an item // arg1: the integer ID of the guild.@id= getarg(0);.@guild_id= getarg(1);
freeloop(1);.@keys= getd("$global_storage_keys"+":"+.@guild_id);.@found= callfunc("array_exists",.@keys,.@id);if(.@found){
freeloop(0);return;}// The new ID was not in the global store, so add it.
callfunc("array_pad",.@keys, getarraysize(.@keys)+1,.@id);
setd("$global_storage_keys"+":"+.@guild_id,.@keys);
freeloop(0);return;}
From this snippet, after I call `setd` with value `.@keys`, the length of `$global_storage_keys:<guild_id>` is always zero.
I'm creating a storage system which allows users to join a group and share a storage between them.
When a group is created, it is assigned an ID. When a player joins the group, they are associated with the group with a permanent account variable.
If Alice is in group 0 and she deposits some items 50 items with ID 10 and 7 items with ID 21, the array `$global_storage_keys:0` should be set to `[10, 21]` and the variable `$global_storage:0:10` and `$global_storage:0:21` should be set to 50 and 7 respectively. However, when I try to update the keys variable with `setd`, only the first value of the array is preserved. How do I manipulate an array which I need to `setd` to access? Thanks.
From this snippet, after I call `setd` with value `.@keys`, the length of `$global_storage_keys:<guild_id>` is always zero.
Share this post
Link to post
Share on other sites