C
ccaalleebbg
Guest
I've been playing with this for like an hour and can't figure out why it isn't working. I'm working on a grid-based inventory system using arrays for a project. Dragging and dropping an item (obj_invItem) around the grid works flawlessly. Taking information from an array called global.invBackpack the obj_invItem changes everything else I want it to just fine, however when I try to reference a variable to set the sprite_index of the obj_invItem it refuses to work.
This code should switch the stored string "invItem01" gathered from the array (in "contents[0]") to "spr_invItem01," allowing me to switch the appearance of the object:
In step event of obj_invItem:
I tested it with draw_text and it's formatted perfectly using that conversion but the sprite wont change. I figured out that it wasn't finding the variable until after the create even but even in the step event it doesn't work.
For reference here's the test code that creates the object I threw in my controller object just to test it:
idgi. Any help would be very appreciated. Cheers.
This code should switch the stored string "invItem01" gathered from the array (in "contents[0]") to "spr_invItem01," allowing me to switch the appearance of the object:
In step event of obj_invItem:
Code:
var spr = string_insert(contents[0], "spr_", 5);
sprite_index = spr;
For reference here's the test code that creates the object I threw in my controller object just to test it:
Code:
if keyboard_check_pressed(vk_space) {
var k = global.invBackpack[1,1];
with instance_create(k.x,k.y,obj_invItem) {
contents[0] = "invItem01";
contents[1] = 5;
}