#Interaction with items via the hot panel

134 messages · Page 1 of 1 (latest)

languid abyss
#

Hi! I have already asked this question on the forum, but no one answered me, I hope they will answer me. I'm implementing a 2D game with a top view. I have a ready-made hotbar with a selection system, and I'm trying to implement an interactive system with objects. For example, when a player chooses a wooden block, he can set it (it will be his own code) or a sword that can be hit (it will be his own code). However, I came across the fact that scripts are activated for all items in slots. If anyone helps, I will be grateful! I am attaching a video with scripts like mine and a screenshot of the "itemdata" script.
https://youtu.be/DaZsCPuDJ5c?si=U6U92dnUQEhvWIGV

fathom falcon
#

can’t your inventory item be just the icon and the data regarding the actual item?

#

That is how I would do at least. I would have a Resource to hold the item information. When assigning to the hotbar I just grab the icon and store the data

#

When I activate it I use the data to spawn the actual item

#

But if you still want to do like you are doing, add a variable to check before running any logic.

#

And change that variable depending of the context

languid abyss
#

Oh, and hello again! I remember you.

#

Hmm, I'll try to do it. As for the first one, if I understood correctly, I have a similar one. Especially the Item resource.

#

I'm sorry for my English, I'm still learning. The fact is that I am trying to implement any way of interacting with objects through the hotbar. The very first thing I thought of doing was a common script with a database about each subject 😅

languid abyss
#

I tried to do a little bit in my own way by searching the Internet, but the script still works for all items

fathom falcon
#

is this the script for the slot?

#

how are you calling this?

#

I need to understand how you have structured things a little more

languid abyss
#

Something like that

fathom falcon
#

why do you have a node for item_data?

#

is oak_log.tres a Resource ?

#

you should use a Resource to populate the slot

#

the point is that you don't need that item_data node

#

and if your hotbar is a child of the player, just set the player variable directly instead of searching the tree

languid abyss
languid abyss
languid abyss
# languid abyss Hmm

It's just that I've seen a lot of people use a resource library where all the item data is stored. I don't quite understand how to then plug in the code for each item

#

Wow, I just changed the code and now each element triggers separately.

languid abyss
fathom falcon
#

You can create an array in your player script and add the resources

languid abyss
#

Thank you!!! And can I use this to create a separate item script and connect it to arrays?

#

Let's say plug in oak_log.gd, which will contain the script to set the tiles. I think that's handy

fathom falcon
#

if you can explain to me what exactly will happen when use the item I can help you further.

#

but you can store a script in the Resource

languid abyss
#

Let's say the oak_log element will have a script to install tiles on tilemap, or some sword will have a script to attack. Something like that.

fathom falcon
#

you can use @export var item_script:Script to store scripts

languid abyss
#

Wow, thanks! This needs to be added to the player.gd, right?

fathom falcon
#

no, the Resource

#

the player holds the arrys with the resources

#

all the data regarding the item goes into the Resource

languid abyss
#

Am I doing everything right? print("hello") command is not executed 😅

#

Or is it necessary to connect arrays in the oak_log script?

fathom falcon
#

You don't need to create a new script for each item

#

you create various resources using the same script

#

here is an example of my weapon data. I ahve one Resource script with the weapon attributes

#

and then I have a folder with the resources created for each weapon

languid abyss
#

Hmm

#

Does this mean that for blocks I need to create a resource "Blocks" and write the same lines as in "Items", but with tile settings?

#

And the "Item" in the form of a sword, and it will have something like yours with similar attributes (damage, etc.)?

fathom falcon
#

not really.
you can use the same script for all since you are storing the script as well

#

and you can have the damage attribute for non-weapons but just not use it

#

another approach is to have a base Resource with all the shared attributes like name, icons, etc. And then different resources per type that extends the base one with the additional attributes

languid abyss
#

Well, thanks! I'll try it later

languid abyss
#

By the way, I wanted to ask. What can I put instead of "print" to call the script? I've already tried a lot, but the script doesn't work

#

I also tried adding arrays

languid abyss
#

Or, instead of "item_script", bind the entire "Item" resource, because all the attributes are there

languid abyss
languid abyss
#

???

languid abyss
#

I also thought that it would probably be worth using the folder where all the resources are located, but how to implement this?

languid abyss
#

@fathom falcon

fathom falcon
#

and you cannot call a script, you need to call a function in the script

#

and depending on the script you might have to instantiate it before using it

languid abyss
#

It's just that now I need to access the created resource for interaction through the hotbar (slot) 😅

#

Of all the guides, this one seemed more approximate because it is from the same author, but I also tried to link it, but nothing worked
https://youtu.be/h90B5vD6noM?si=95O-5SaHZy3GTd93

Item System using Custom Resource, with a mini Action bar and implementing a throwing axe in Godot 4

Slot - https:...

▶ Play video
languid abyss
#

I'm still trying to figure out how to implement it and the ideas are very close, but at the same time not 😅

languid abyss
#

I tried, but it still doesn't work. In addition, strange errors have appeared.

#

Can I use signals to connect to resources?

languid abyss
#

slot and player

#

I think I need to access the item_data where all the resources are listed, but I don't understand how

fathom falcon
#

hey

#

do you have an example of an item script?

languid abyss
#

Could you tell more about this? I'm a little confused 😅

languid abyss
fathom falcon
#

I don't think you need though

#

I have to go now

#

I can help you some other time

languid abyss
#

Well, all right. Good luck! Maybe I'll try to figure it out myself. All that remains for me is to get access to resources, and I understood the rest

languid abyss
#

https://www.youtube.com/watch?v=E-GgHGJANkc
If you're still here, I wanted to do roughly the same thing. You can chop trees with an axe, or you can lay tile. This is just an example, and hopefully my point is clear now.

Creating a simple hotbar that can equip items to the player's hand by clicking on the tool button for the tool you want to equip.

Series Playlist ➣ https://www.youtube.com/playlist?list=PLyH-qXFkNSxlANk9EwZmbtECBfbHeW68-
Full Project with Scripts, Assets, and Art Pack ➣ https://ko-fi.com/s/e848d87222
Art Pack ➣ https://chris-tutorials.itch.io/g...

▶ Play video
#

For example a stick can be used as a tool and a block of earth set on a TileMap

#

That's the only thing I'm having trouble with right now. It seems to be ready, but not to the end

languid abyss
#

If necessary, I can show my scripts

fathom falcon
#

I see. But I am not sure you need to run a different script for each item. You just have 2 or 3 categories that would dictate which action to apply (use, place, etc). Or that action can even be a string you write for each Resource.

#

Tip: you can create an enum for the item type instead of a string:

enum ItemType {WEAPON, ARMOR, CONSUMABLE}

@export var type:ItemType
fathom falcon
#

you don't need a use_item function in the Item.gd. That just needs to hold the item information. So you when use the item through the hotbar, you just pass the data to the player.

#

and depending on what is the type, the player script can do what is need (place, use, wear, etc)

languid abyss
#

Oh, thank you so much for still trying to help me. I will definitely try and report the result!

languid abyss
#

I think I'll try to test it tomorrow

languid abyss
#

The point is that Item.gd already has these lines or do they need to be added somewhere else?

#

slot.gd and player.gd
What can I put in there to connect item types? (weapon, consumable, armor and etc)

#

This topic seems a bit confusing to me, but hopefully I'll understand and learn everything 😅

fathom falcon
#

You just have to pass the whole Resource around

#

I think in that case you are calling it stats

#

So you can check stats.type

fathom falcon
languid abyss
#

Okay, thanks! I will also try this

languid abyss
#

I tried to do this and print really reacts to type

#

But what should I insert instead of these lines, or is it better to delete them? They are responsible for calling activation in the slot

#

But at least there was some result.

#

Something like that?

fathom falcon
#

in the Character script you can write the logic to use the icon according to its type

#

why do you have 2 parameters to add the item to the hotbar?

languid abyss
languid abyss
#

By the way, while I'm still trying to implement this system, I'd like to ask you something else. I've already started learning GDScript, but how would you recommend doing it? Perhaps there are still better ways?

fathom falcon
#

That’s basically how I would it. Store the data on a Resource and pass it around with signals or functions.

#

I always try to keep systems as data driven as possible

languid abyss
#

Thanks

languid abyss
#

https://youtu.be/SB0QrnI_-IQ?si=E1K-Dta9gFl8zxNy
I saw this video in the recommendations and he also explained it very clearly. I can try to combine your answer and the video

In this video, we’re creating a modular weapon system for my first person shooter project. We’ll be using scripts and custom resources so we can quickly save weapon attributes and swap between weapons efficiently.

🔥 GET THE SOURCE FILES ►► https://www.patreon.com/StayAtHomeDev_
👉🏼 FREE BASIC FPS SETUP SOURCE FILES ►► https://github.com/StayAt...

▶ Play video
languid abyss
#

And so, after a short break, I'm back here. Here I have a script for installing tiles. I will try to combine all this

fathom falcon
#

Are you calling that function in the process function?

#

Also, if you want to create a constant for your layer, do it outside the function, so it gets created only once. And use const instead of var

languid abyss
#

Okay, thanks, I'll take it into account

languid abyss
#

I have tried, but so far without success

#

But I'll do something else.

fathom falcon
#

you still could not make the hotbar work?

#

what specifcally is not working now?

languid abyss
languid abyss
languid abyss
fathom falcon
#

why can't you call the function?

#

can't you use a signal for that?

languid abyss
languid abyss
#

I'm thinking how this can be implemented. I just don't quite understand, as you said, why in this video he uses interactive items twice.

fathom falcon
#

I didn't watch the video

#

where is the function and from where you want to call it?

languid abyss
#

player

languid abyss
#

So far, print only works with item types

fathom falcon
#

the item type line is not doing anything

languid abyss
#

Can we move on to private messages? It seems to me that there are already too many posts on this forum, and it's a little inconvenient 😅