playMaker

Author Topic: Access PlayMakerHashTableProxy from scipt  (Read 1694 times)

looi

  • Playmaker Newbie
  • *
  • Posts: 21
Access PlayMakerHashTableProxy from scipt
« on: May 16, 2018, 06:43:08 PM »
Hello!

First of all, I know this is more relative to a C# understanding than PlayMaker itself, even so, I would appreciate your help.

I've filled a playmaker hashtable with all NCS colors with their key names, now I need to access them from a script. I've managed to read all the values, but I cannot convert them to UnityEngine.Color32 to be able to operate them and to do all calculations I want to do with RGB, etc.

Code: [Select]
foreach (DictionaryEntry colorInTheList in NcsList.hashTable) {
     Debug.Log(colorInTheList.Value) //it prints RGBA(0,0,0,0) the color!
     Color32 colorValue = colorInTheList.Value
}

with this code, the console says "error CS0266: Cannot implicitly convert type `object' to `UnityEngine.Color32'. An explicit conversion exists (are you missing a cast?)"

Thank youuu!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Access PlayMakerHashTableProxy from scipt
« Reply #1 on: May 18, 2018, 09:54:32 AM »
Hi.

Is colorInTheList an fsm value?

Can you show more from the script?

As i believe that hash table values are not using fsmvariables.

looi

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Access PlayMakerHashTableProxy from scipt
« Reply #2 on: May 18, 2018, 01:04:32 PM »
Finally I found a workarround: to parse the DictionaryEntry.Value. I know this is nonsense, but It works for me and I do not reach something better.
This is the entire function:

Code: [Select]
public void closestColor3(Color32 target){
float hue1 = getHue (target.r, target.g, target.b);
var num1 = ColorNum(target);
float minimaDiferenciaColores = 10000;
string key="";
int flag = 0;
int index = 0;
Color valor; Color32 valor32; Color colorParecido = new Color();
foreach (DictionaryEntry colorDeLaLista in listaNcs.hashTable) {
flag++;
float Rvalor = float.Parse (colorDeLaLista.Value.ToString ().Substring (5, 5));
float Gvalor = float.Parse (colorDeLaLista.Value.ToString ().Substring (12, 5));
float Bvalor = float.Parse (colorDeLaLista.Value.ToString ().Substring (19, 5));
valor = new Color (Rvalor,Gvalor,Bvalor);
valor32 = (Color32)valor;
float diferenciaColores = Math.Abs(ColorNum(valor) - num1) + getHueDistance(getHue(valor32.r, valor32.g, valor32.b), hue1);
if (diferenciaColores < minimaDiferenciaColores) {
minimaDiferenciaColores = diferenciaColores;
key = colorDeLaLista.Key.ToString ();
index = flag;
colorParecido = valor;
}
}
img_NCS.color = colorParecido;
txt_NCS.text = key;
}

If you have any suggestion to improve it, please tell me. Thanks! :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Access PlayMakerHashTableProxy from scipt
« Reply #3 on: May 22, 2018, 05:05:08 AM »
Hi,

 If you can give an example of your content, I can have a look at the best way to parse your string into a valid Unity color.

 Bye,

 Jean