playMaker

Author Topic: Looking for a shortcut for saving 300+ objects in variables [SOLVED]  (Read 306 times)

krmko

  • Sr. Member
  • ****
  • Posts: 426
    • View Profile
    • Fat Pug Studio
Hello,

I made a 2D 15*21 grid (A1/A21-O1/O21) of gameobjects that will be added to arraylist and used for random spawning locations by getting a random arraylist item and using its location. But i also need the possibility to target the exact gameobject i wish to use as a target location (for example G13).

Normally, i would use get owner action and store the gameobject in a gameobject variable under its name, but when i think of the work needed to create FSM on each object to get owner and store it under a different variable, my head hurts.

Any elegant way of solving this?
« Last Edit: October 01, 2017, 11:03:21 PM by krmko »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #1 on: September 26, 2017, 08:26:14 PM »
Hi,
I am not exactly sure what you mean, but i give it a try.

for a grid you need to use multiple arrays, one for each line or row.

you can name them A,B,C and so on the for you index you need to use 0 to 20
if you want to use 1-21 you can add 1 to the result when needed.

now you can place all your object into the arrays.

Then you can use mouse pick to select an object and store it into a variable.
Then use Array contains on each row in sequence (A, B, C) and store the index result (if your 'array contains' does not have the 'index result' re-download the package as it is added recently)
and send event for each array list (A for A, B for B and so on.

Now you have your grid position of your object.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #2 on: September 26, 2017, 08:33:26 PM »
I'm just thinking,
Maybe you can use Hash Table instead with a customized  Hash Table Contains that would store the index and the key.
this way you would not need 15 transitions.

I will try to make the action in the next days if you want.

krmko

  • Sr. Member
  • ****
  • Posts: 426
    • View Profile
    • Fat Pug Studio
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #3 on: September 27, 2017, 01:47:02 AM »
I'll try and explain it a bit better. This is the screenshot with the grid, every X is an object used for positioning, A1, A2, A3, B1, B2, B3, etc.



I spawn the stuff with Core Game Kit Pool Boss spawn and i simply use the object itself (get owner) via other object for position or (get position) spawn location.



Whatever approach i use, i need to put an FSM on each of the X object and store either the gameobject or location to a reference. As you can imagine, it's a lot of copy pasta, so i was wondering if there's an easier way.

I even tried a different approach, to open empty vector3 and gameobject global variables and then edit the playmakerglobals.asset, but those variables don't appear there?

krmko

  • Sr. Member
  • ****
  • Posts: 426
    • View Profile
    • Fat Pug Studio
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #4 on: September 27, 2017, 03:43:22 AM »
Hi Djaydino,

i appreciate the effort, but i never used hash tables and i don't know how they work. I know the basics, the key (name) and value. I lookup the key and get value. They're a lot better than arrays because they represent a kind of a spreadsheet, which is superior to arrays.



But i don't know how would that help me reduce manual labor of filling in variables.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #5 on: September 27, 2017, 09:24:40 AM »
Hi,
The keys can be names, so you could set the keys A1,A2...O1, O2....
or 01,20,0 (vector 3 position)

using a 3rd party asset to spawn them, makes it indeed harder.

Are they spawned @runtime or in editor?

If on runtime,
Maybe something like this :

on start you need to place the gameobject with the Hash Table into a global variable to reference from the prefabs

(you need to be sure that the gameobject with the Hash Table is placed in the global before doing the next thing on the prefabs. maby use a next frame event on the start of the prefab if they are spawned @ the start of the game)

Then on the prefab you need a 'get position' to get the position and convert it to a string variable.

Then you need a "Hash table add" and as gameobject you need to set the global variable.

for the 'Key' you can use the string you got from the position.
(Waring!! keys can not be the same name, so each position should be unique)
and for the variable , set it to gameobject and drop in the gameobject.

Now you can use a mouse pick to select an object and then use "Hash Table Get Key From Value" to get the position.

krmko

  • Sr. Member
  • ****
  • Posts: 426
    • View Profile
    • Fat Pug Studio
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #6 on: September 27, 2017, 11:53:48 AM »
Hi Djaydino,

no, no, no, those red X's are already in the scene, they don't need to be spawned on runtime, i justed turned on their renderer so they can be seen. They are already named A1, A2...their location will be used for spawning enemies on runtime, and enemies need just need a vector3 or gameobject reference.

Wow, that seems a bit complicated, but i'm sure it's easy, i'll give it a shot and let you know!


krmko

  • Sr. Member
  • ****
  • Posts: 426
    • View Profile
    • Fat Pug Studio
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #7 on: September 27, 2017, 02:58:35 PM »
Damn, i did it with your help, but a bit differently.

First i put all the children of the game object that contains grid game objects to array and then i start iterating and adding the result to array item gameobject variable. For every interation i get the items name and store it in string variable, then i add it to hash table with string variable being the key, and variable in the table being the array item gameobject. Then i get the next one and so on until the hash table is full.

But! There are three problems.

The first one is that by using Array List Get All Child Of Game Object parent of the grid elements is also added to the array. I don't know if it's a bug, badly written action or i'm doing something wrong. Sure, i can remove it from the hashtable when everything is done but i'd really like to know what's happening.

Second, all of these shenanigans take whopping 7 seconds to complete. Any way of doing it faster?

Third, how do i save the hash table so the variables are available out of runtime? I basically want to create gameobject variables so i don't have to click new variable, A1, drag gameobject 300 times.
« Last Edit: September 27, 2017, 04:00:28 PM by krmko »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #8 on: September 27, 2017, 10:46:06 PM »
Hi,

The first one:
It should indeed only get the children and i tried to set the parent inactive but that did not help. i will try to check that action later.
(or contact the author from this action)

Second :
I am not sure why it takes so long

Third :
play, then after everything is placed in the array proxy,
Right click on the array list proxy and select 'Copy Array List Content'
Then stop and right click again and select 'Paste Component Values'



jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #9 on: September 28, 2017, 12:09:51 AM »
Hi,

Ok, I added this action as part of the main ArrayMaker Package and I added the option to ignore the parent.

 So get the latest ArrayMaker and use the built in action.

 Bye,

 Jean

krmko

  • Sr. Member
  • ****
  • Posts: 426
    • View Profile
    • Fat Pug Studio
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #10 on: September 28, 2017, 02:09:48 AM »
@Djaydino

Hi, if you mean "copy component" and then "paste component values" that doesn't work, the array stays empty  :-\

Ah, my arraymaker wasn't updated, it works now, but i have no idea how to save each item as a variable automatically, without having to manually create each variable and assing the gameobject as a value.

@Jean

Thanks for the action!
« Last Edit: September 28, 2017, 04:09:51 AM by krmko »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #11 on: September 28, 2017, 11:44:53 PM »
Hi,

 I think you are not fully grasping the principle of arrays,. you should not create a variable per item, but instead ask the array for a particular item. So you will need to drop the 300 objects in the array, but you should not create 300 hundred gameobject variables.

also, few ways to automate the process:

- one way is to have your 300 objects as prefab, each setting themselves inside the array
- each fire a global event the manager catches these events and store the senders in the array
- you attach all the 300 objects to the same parent, then store each children in the array using a loop and an action that returns all children of a given object.

 Bye,

 Jean

krmko

  • Sr. Member
  • ****
  • Posts: 426
    • View Profile
    • Fat Pug Studio
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #12 on: September 29, 2017, 01:22:08 AM »
You're probably right about that, but you must agree it's probably faster to just select a variable out of a list then get an item from the array, store it in a variable and assign it as a spawn point :)

Anyway, thanks for the help guys, it means a lot to me!

krmko

  • Sr. Member
  • ****
  • Posts: 426
    • View Profile
    • Fat Pug Studio
Re: Looking for a shortcut for saving 300+ objects in variables [SOLVED]
« Reply #13 on: October 01, 2017, 11:25:29 AM »
Oh hi,

one more issue before i finally solve this. I have 240 items to add to the array, then to a hash table and then use their position for spawning. They are childed under a parent so i can easily add them with array list get all child of game object.

But the problem is that that way their position is saved as local to the parent whereas i need their GLOBAL position. If i de-child them, i have no idea how to put them by not dragging and dropping them in the array/hash table one by one.

Though i suppose i could copy/paste an fsm to every object whose sole purpose would be to add the owner to the array.
« Last Edit: October 01, 2017, 11:38:03 AM by krmko »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2305
    • View Profile
    • jinxtergames
Re: Looking for a shortcut for saving 300+ objects in variables
« Reply #14 on: October 01, 2017, 04:59:46 PM »
Hi,
I think your best bet is to copy/paste an fsm that uses get position and array list add
and/or hash table add
once done and saved the array/hash table you can remove the fsms.