Scripts / [SOLVED] I need help with my inventory script - Sprites not working

Author
Message
Duncan_Idaho
5
Years of Service
User Offline
Joined: 29th Jul 2019
Location:
Posted: 10th Oct 2023 00:50 Edited at: 10th Oct 2023 01:03
This post has been marked by the post author as the answer.
I am working on an inventory script for a game and I've been trying to get this script working for a week. My Problem: I've got an array/list with Items - in this array there is a string which contains the file path. I aimed that my logic would create and name the sprites automatically. but it seems there is a problem with that logic and I can't find a way to fix that problem.

Sorry for my bad english - I am not a native speaker and I didn't sleep very well the last days, because of this little problem

Edit: ok I got it working - I changed the Init-Function:

function da_inventory_init(e)
Error_Img = LoadImage("scriptbank\\DuncanArts Universal Mouse mode\\inventory\\images\\No_Image_Found.png")

for itemName, item in pairs(items) do
local itemImage = LoadImage(item.ImgPath)
if itemImage then
-- Erstelle eine Sprite für das Item
local spriteName = itemName .. "_Sprite"
g_InventorySprites[spriteName] = CreateSprite(itemImage)
SetSpriteSize(g_InventorySprites[spriteName], 5, -1)
SetSpritePosition(g_InventorySprites[spriteName], -200, -200)
else
ShowErrorMessage("Error loading image for item: " .. item.name)
end
end

-- Füge eine Sprite für den Fehlerfall hinzu
g_InventorySprites["Error"] = CreateSprite(Error_Img)
SetSpritePosition(g_InventorySprites["Error"], -200, -200)
SetSpriteSize(g_InventorySprites["Error"], 5, -1)
end

Everyone, who wants, can use this script under CC0-Licence

@all: Thank you for this great forum, which helps me to learn, how to code

The author of this post has marked a post as an answer.

Go to answer
PM
Duncan_Idaho
5
Years of Service
User Offline
Joined: 29th Jul 2019
Location:
Posted: 10th Oct 2023 01:04
here the working code
PM

Login to post a reply

Server time is: 2024-11-02 08:57:04
Your offset time is: 2024-11-02 08:57:04