Label an array of buttons with an array of strings

Hello,

I’m trying to label an array of buttons using an array of strings, but I get an error message saying: “Ambiguous reference ‘Button’: UnityEngine.GUI.Button(UnityEngine.Rect, UnityEngine.GUIContent), UnityEngine.GUI.Button(UnityEngine.Rect, UnityEngine.Texture), UnityEngine.GUI.Button(UnityEngine.Rect, String).”

I’ve looked through some answers here but could not solve my problem. What I’ve got so far is:

var estCas : Array = new Array[9];
function OnGUI () {
    for (var i = 0; i <= 8; i = i++){
        if (GUI.Button (Rect (posX, posY, size, size), estCas*)) {*

}
}
}
Funny is that if I concatenate estCas with an empty string it works, well, somewhat, unity crashes a couple seconds later and the buttons won’t even appear.
Any help will be realy, realy apreciated!
*Edit (Adding full code)
What I’m trying to do is simple a Tic Tac Toe game as I’m begining with programming.
var cell : Array = new Array[9];
var cellEst : Array = new Array[9];
var turn : boolean; // false = X; true = O

function Start () {
* for (var i = 0; i <= 8; i = i + 1){*
_ cellEst = “”; //Gives an empty string that can later be changed to X or O
* }
}*_

function OnGUI () {
* for (var i = 0; i <= 8; i = i + 1){*
//Arranges the buttons into an tic tac toe board
* var posX : int = 0;*
* var posY : int = 0;*
* var size : float = 100;*

* if (i == 1 || i == 4 || i == 7) {*
* posX = size;*
* }*

* if (i == 2 || i == 5 || i == 8) {*
_ posX = size * 2;
* }*_

* if (i == 3 || i == 4 || i == 5) {*
* posY = size;*
* }*

* if (i == 6 || i == 7 || i == 8) {*
_ posY = size * 2;
* }*_

if (GUI.Button (Rect (posX, posY, size, size), cellEst_) && cellEst == “”) {
* if (turn == false) {
}*_

* else {*
* }*

* turn = !turn; //Changes player*
* }*
* }*
}
*** FIXED CODE ***
var estCas : String = new String[9]; //Don’t forget to add a value to the called index
function OnGUI () {
for (var i = 0; i <= 8; i = i + 1){ //Unity crashed when I used i++
if (GUI.Button (Rect (posX, posY, size, size), estCas*)) {*
}
}
}
Thanks a lot to Dave A, Eric5h5 and Owen Reynolds!!!

I’m betting that estCas is declared like:

var estCas; or var estCas = new Array(); or something like that.

try this:

var estCas : String;

Your loop should use “i is LESS THAN 8” or else make the array be size 9.

The size 8 array has indexes from 0 to 7 (which is 8 things.) The loop runs (i=0; i<=8 ...), which is 9 things. The ninth button is using past-the-end string estCas[8]. In C# that’s an array-out-of-range error. Javascript it just makes up a Object value, which confuses Button and gives the odd error you saw.