playMaker

Author Topic: Pass data to a spawned object?  (Read 3971 times)

weavermount

  • Playmaker Newbie
  • *
  • Posts: 2
Pass data to a spawned object?
« on: April 03, 2015, 10:14:41 PM »
I have FSM that keeps track of the time between mousedown and mouse up, then spawns (via pathological pool manager) a projectile. How to I inform the projectile how long it was charged for (the time between mouse down and mouse up)?

I need to figure out some way to get it that information before it's drawn for the first time. Any best practices? I can think of a lot of akward hacks, but nothing that feels good.

Thanks in advance

TheBadFeeling

  • Junior Playmaker
  • **
  • Posts: 66
Re: Pass data to a spawned object?
« Reply #1 on: April 04, 2015, 06:46:31 PM »
How about having the "creator" save the new object in an object variable when you spawn it -- and immediately after pass the data to it using Set FSM Variable?

/Bad
The Force is with you, young Playmaker – but you are not a C# senpai yet.

weavermount

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Pass data to a spawned object?
« Reply #2 on: April 06, 2015, 02:54:50 PM »
Turns out I'm just not used to exactly how the two FSMs were timing there states.
I might not be very FSMonic( ... FSM-ly?) but I made an empty "Hold for data" State followed by and "Init" state followed by a "Fly" state. Once I told it to wait for data before using it it cleared up

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Pass data to a spawned object?
« Reply #3 on: April 06, 2015, 03:06:44 PM »
Typically you can spawn and set the data in the same state. For instance using Create Object, storing the reference to the new object and immediately using Set Fsm <type> on that object reference. You could additionally fire an event on that FSM after you've set the data, like a "ready" event that is fired from an empty Start state.

I find that nearly all of my start states are used for initialization. I don't typically require a 'handshake' event like that, but it seems like a good idea.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Pass data to a spawned object?
« Reply #4 on: April 07, 2015, 03:20:09 AM »
Hi,

 yep, I confirm Lane's post. instanciate your prefab, and set fsm variables on it directly, it works.

 I usually have a small handshake like an "INIT" global event or something when I need asynchronous process, typically, if the operation involving the creation of the instance has more to do after to get everything setup.

It's also good to send a quick "INIT", because then the instance can get who sent that INIT event ( using get event info action) and talk back very easily (without the need for global variables :) )


 Bye,

 Jean