Skip to main content
March 5, 2016
Question

How to convert a Boolean to a String?

  • March 5, 2016
  • 1 reply
  • 1343 views

Hey there, I'm tinkering around with flash trying to build just a fun little RPG for myself. I'm currently trying to make an inventory and I've run into a problem. I was wondering if I am able to convert a boolean into a string (doesn't matter if an if statement is used).

Basically when I click on an item I want it to check what the first open spot is and go there. I'm doing this by having a for loop, each iteration of the loop it creates a string with the value "slot" + currentNumberInForLoop. I have named my inventory slot booleans, slot0, slot1, etc. I want to convert these booleans to strings, check if they equal the other string, and keep going through until it is found true (an open inventory slot).

If you need further clarification on my question let me know (it's 4am and I'm tired )

Thanks,

Eric

This topic has been closed for replies.

1 reply

Inspiring
March 5, 2016

var slot:Boolean = true;

var _string = String(slot);

trace(string);

kglad
Community Expert
Community Expert
March 5, 2016

you can use slot.toString() but your setup/premise is faulty.  your slots shouldn't be booleans.

generally, you'd use:

var slots:Array=[];

and then add inventory items to your slots array.

March 5, 2016

I was thinking about going about it that way but I wasn't sure how. Do you have a general idea on how to?