playMaker

Author Topic: How to convert an GameObject to an Object?  (Read 4543 times)

phannDOTde

  • Full Member
  • ***
  • Posts: 237
    • Peter Hann .de
How to convert an GameObject to an Object?
« on: February 04, 2014, 03:08:53 PM »
Im was playing around with Array maker and tryied to get some 3D Text Gameobject from an Array list and setting its Text with set Property, since I only can put Gameobjects into the Array List I'm unable to set Property at the Gameobject without converting int to an Object. Any hints here?

Cheers
Peter

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to convert an GameObject to an Object?
« Reply #1 on: February 04, 2014, 03:21:38 PM »
Objects and GameObjects are different things.

Use Get Component to get UnityEngine.TextMesh.Text from your target 3D Text, then use Set Property and fill the text you want or choose a variable.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

phannDOTde

  • Full Member
  • ***
  • Posts: 237
    • Peter Hann .de
Re: How to convert an GameObject to an Object?
« Reply #2 on: February 04, 2014, 03:41:32 PM »
I know that they are different things BUT how should I dynamicly make a  get Component from an GameObject - I CANT store Objects with Array Maker - so I need to somehow convert the storred Game Object into some kind of Object that I could use with the "Get Component" Action. (Or am I missing something here)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to convert an GameObject to an Object?
« Reply #3 on: February 04, 2014, 03:55:54 PM »
Once you get the 3D Text GameObject out of the array and store it in a local variable then you can do whatever you want to it.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to convert an GameObject to an Object?
« Reply #4 on: February 04, 2014, 04:01:01 PM »
Also, storing Component Objects works just fine in ArrayMaker, so you could just go directly to that.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

phannDOTde

  • Full Member
  • ***
  • Posts: 237
    • Peter Hann .de
Re: How to convert an GameObject to an Object?
« Reply #5 on: February 04, 2014, 04:35:35 PM »
Hmmmm maby I oversee something here but on the prefill type of an array I cant select "Object" only "GameObject" is Valid.

And I cant figure out how to "get Component" from this GameObject :-/

Maybe I should sleep over it and give it another try tommorrow

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to convert an GameObject to an Object?
« Reply #6 on: February 04, 2014, 05:10:09 PM »
Yep, getting a fresh look at things after a nights sleep is good :)

I'm not sure why you can't prefill Object types, but it works just fine doing them at runtime. It may just be due to their nature or the fact that you couldn't drag and drop them. This could probably be a supported feature but is more complex for little return so it was decidedly omitted.

If you have an array of GameObjects then...
1. Use Array List Get to store the GameObject locally
2. Use Get Component to store a Component on that GameObject. (this requires you make an Object variable and choose which component you want from that GameObject before ever actually getting it. Get Component will look at the variable, then get the component from the target GameObject and store it there.)
3. Use Set Property, target that Component, change the text variable. You can fill with a string variable or set it explicitly in the field.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

phannDOTde

  • Full Member
  • ***
  • Posts: 237
    • Peter Hann .de
Re: How to convert an GameObject to an Object?
« Reply #7 on: February 04, 2014, 07:25:21 PM »
Thanks for your help Lane,

I look into that tomorrow - got another issue that I cant figure out. I want to use an Array to store several Highscores in my Game. Now I would love to sort them with the Array Sort Action. This aint a Problem as long I got only Integers to sort - but i cant figure out how to i.e. store the Playername acording to a Score Integer. If I make a string out of them like Score*Name, they cant be correctly sorted (only the firts digit is taken in acount since they are strings now), if I got seperated Arrays for Names and Scores I have no idea how to make sure they match again after I sort the Score array .... hope you get what my Problem is and maybe you got another Hint on this one too?

cheers and good night :-)
Peter

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to convert an GameObject to an Object?
« Reply #8 on: February 05, 2014, 04:29:31 AM »
Hi,

 use hashtables instead of arrayList for scoring ( name->score )

 As for object entries for ArrayMaker, yes, it's simply a question of interface, I am not sure how to present a flexible enough selection system for objects. And yes, Lane is correct, at runtime using actions, no problem.

bye,

 Jean

phannDOTde

  • Full Member
  • ***
  • Posts: 237
    • Peter Hann .de
Re: How to convert an GameObject to an Object?
« Reply #9 on: February 05, 2014, 10:18:14 AM »
Thanks Jean, but how would I sort a hash table score list? Didnt find any "Sort Action" there.

(sorry for the noob questions but arraymaker isnt that much of an easy thing for my without documentation and coming from a different Approach)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to convert an GameObject to an Object?
« Reply #10 on: February 06, 2014, 05:11:03 AM »
Hi,

 It's a bit difficult to do that currently. At least not in an easy way unfortunatly. Hashtable are not sortable by definition.

I have added this to my todos for the ArrayMaker task, I will provide a system that for example allow you to define a sorted list, as opposed to a hashtable, or simply create a list of keys sorted based on a hashtable,

I'll have to experiment with this...

https://trello.com/c/FamlVQBD/31-arraymaker-update


bye,

 Jean