Creating Attributes in a Behavior

FireDart

  • Posts: 5
Hello!
 I am creating an inventory system for a game. It uses a loop where it repeats once for each item on the inventory list; what I want it to do is create a region for each item so that it can be clicked on to equip the selected weapon. My problem is that, without having a theoretically infinite number of region attributes pre-made in the scene behavior, I can't have a theoretically infinite number of items in the inventory. My problem would be solved if I could find a way to create a Region attribute in the loop, so that a region attribute is created for each item on the list. Is there a way this can be done? I feel like I'm missing something pretty obvious.

Justin

  • *
  • Posts: 4626
If you're stuck on creating a region itself, there's this block



https://www.stencyl.com/blocks/view/scene-regions


But it sounds like maybe you just want a lot of attributes to refer to regions? You can put regions into a list or map attribute. For readable code, perhaps use a single region attribute to temporarily hold list items retrieved from the "get/set item in list" block in your loop.
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

FireDart

  • Posts: 5
Thanks for the response!
 Using your idea, I created a list called "InventoryItems." After creating the region in the previously mentioned loop, I add the last created region to "InventoryItems." I then have an Input on Region event, whose condition is "When the mouse is pressed on (get item #1 from InventoryItems)." Unfortunately, when I click on the region associated with item #1 on "InventoryItems" nothing happens.

 I used draw blocks to see what was being written into the different indexes of the list, and here is what printed;
  Index 0:   Test
  Index 1:   [Actor 1,Region]
  Index 2:   [Actor 2,Region]
  Index 3:   [Actor 3,Region]
  Index 4:   null
 (There are currently 3 items in the inventory; the value of the first index of the list is text a text attribute which reads "Test".)

 The problem seems to be that the Input on Region event isn't recognizing [Actor 1,Region] as a region. I'm guessing that when a region is added to a list it is converted to text; if this is the case, how can I convert the text back into a region? Thanks for your time!
 

Luyren

  • *
  • Posts: 2727
You'll have to post a screenshot of your code for better help. To my understanding, nothing is automatically converted to anything when added or inserted into a list.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

FireDart

  • Posts: 5
Here are the two events involving the regions;

Justin

  • *
  • Posts: 4626
It's only converted to text when you print/draw it. What's in the list is a region, no need to worry about that.

The problem here is the timing of the "when the mouse is pressed" event registration.

1. A scene is entered / an actor is created.
- 1a. "When created" events are executed.
- 1b. Other events are not executed, but their conditions are registered. This is when "get item #1 from InventoryItems" is evaluated.

So for the region to exist at index 1 in your list by the time that the event is registered, it would need to be added to the list in your "when created" events.

Perhaps instead of using events, you could loop over the regions and check which if them was pressed (perhaps within a general "mouse was pressed" event, to avoid performing the calculations every game step).
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)