使用此函数,您可以从指定的密钥获取值。函数的输入值是要使用的(先前创建的)DS映射和检查的密钥。
注意 如果不存在此类键,则该函数将返回 undefined。您应该始终使用 is_undefined() 函数进行检查。
ds_map_find_value(id, key)
参数 | 类型 | 描述 |
---|---|---|
id | DS Map | 要使用的映射的ID。 |
key | String | 找到的关键。 |
amount = ds_map_find_value(inventory, "food");
或者,使用map访问器"?":
amount = inventory[? "food"];
上述代码将获得键"food"的价值,并以可变的"amount"存储。