Spawn object location based on array index

Get help using Construct 2

Post » Sun Feb 28, 2016 9:07 pm

Message: GuyManDude can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
I want to be able to spawn objects in locations based on their array index number. I am trying to spawn them in a corresponding image point on a sprite. When I click the button to run the UpdateBagView function it creates a bunch of objects at the sprite origin (number 0) and not on the correct image point. It an item has say array index 2 I want it to spawn on image point 2.

Here is a capx
http://1drv.ms/1Tg3YSU

Drag objects onto the bag to add to array.
Right click an object to delete from array.

This capx has a number of problems I could use help figuring out please.
B
8
S
1
Posts: 27
Reputation: 515

Post » Sun Feb 28, 2016 10:32 pm

You can't spawn Family objects - you get a random object. You need to decode the name and spawn that item. Use Array.CurX+1 instead of IndexOf in event 4. Also, get rid of the Foreach in event 2 - you have that already in event 4.
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Tue Mar 01, 2016 4:51 am

Message: GuyManDude can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Thanks for the help. Your suggestions definitely improved it a lot. I now have a situation where adding the second item to the bag spawns a bunch of stuff even though it is a function that I expected to limit it to one. Would appreciate you taking a look at the latest version when you get a min please.

Capx:
http://1drv.ms/1Tg3YSU
B
8
S
1
Posts: 27
Reputation: 515

Post » Tue Mar 01, 2016 5:18 am

You are doing it again. You call Foreach at event 11 and again at event 4, so every time you add and item, you call UpdatebagView, and then again for every item spawn an item.

Are you going to need to read the array from storage at some point and fill the bag again, or are you only filling the bag as each item is dragged in. This will make a big difference to the proper answer.
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Tue Mar 01, 2016 6:11 am

What I want to get to is a bag that I can drop items into that updates immediately, and if an item is dragged out of the bag the slot is emptied. I want the next item to go into the empty slot. I guess like a real bag would act.

I understand the spawn and respawn problem but I am struggling to deal with it. In fact, event 10 has a second condition that was my attempt at limiting the function running again if the item had already had its local variable InBag set.

Thanks again.
B
8
S
1
Posts: 27
Reputation: 515

Post » Tue Mar 01, 2016 7:13 am

ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Wed Mar 02, 2016 2:54 am

Wow, you nailed it. I'm still trying to get my head around your code. Could you explain exactly what events 19-21 do please? Your comment helps but I'm lost.

BTW, If I wanted to run this code on a separate layout and fall back to a previous layout during game play, are there any gotchas I should consider? My game has the player visiting a closet (calls another layout) where the items that will go in the bag actually reside and exiting the closet takes the player back to the previous layout.

Thanks again for all the great help BTW.
B
8
S
1
Posts: 27
Reputation: 515

Post » Wed Mar 02, 2016 3:13 am

19a: check that the index you are removing from is not the last one
19b: loop from the NEXT index to the last index
20: pick only "InBag" stuff (this could technically be moved up, but that's a minor optimization)
21: pick the Stuff with the name at the current index we care about
-> move the single Stuff

This shows how to get the whole bag filled again (I am not dealing with the duplicate items. I'm just showing how to get the items to show in the bag, when the array already has data in it.)

http://www.blackhornettechnologies.com/ ... fresh.capx
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692


Return to How do I....?

Who is online

Users browsing this forum: max2612 and 5 guests