Reputation: 1
I'm having issues with this code its for a card game called war, the error says "Line: 53: setText() text parameter value (undefined) is not a uistring" and I tried editing the code in a whole new way and it's keeps saying it.
var A=14;
var J=11;
var Q=12;
var K=13;
var cards = [A, "2", "3","4","5","6","7","8","9","10",J,Q,K ,A, "2", "3","4","5","6","7","8","9","10",J,Q,K,A, "2", "3","4","5","6","7","8","9","10",J,Q,K,A, "2", "3","4","5","6","7","8","9","10",J,Q,K,];
var PlayerCards=[];
var AICards = [];
var playerScore = 0;
var AIScore = 0;
var aArr =0 ;
var pArr = 0;
cards = shuffle(cards);
dealPlayerCards();
dealAICards();
onEvent("War", "click", function(event) {
setScreen("gameGrounds");
});
onEvent("flipcard","click",function(event){
game();
playerScore= playerScore;
AIScore= AIScore;
aArr = aArr +1;
pArr = pArr +1;
winLose();
});
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
function dealPlayerCards(){
for (var i = 0; i<= 25; i++) {
var chooseCard = randomNumber(0,cards.length-1);
appendItem(PlayerCards,cards[chooseCard]);
removeItem(cards,chooseCard);
}
}
function dealAICards(){
for (var i = 0; i<= 25; i++) {
var chooseCard = randomNumber(0,cards.length-1);
appendItem(AICards,cards[chooseCard]);
removeItem(cards,chooseCard);
}
}
function game(){
setText("playerCard", PlayerCards[pArr]);
setText("aICards", AICards[aArr]);
if (PlayerCards[pArr] > AICards[aArr]){
playerScore =playerScore+1;
setText("playersScore",playerScore);
}
else{
AIScore =AIScore+1;
setText("AIsScore", AIScore);
}
return;
}
function winLose(){
if(playerScore >= 17){
setScreen("win");
}
if(AIScore >=17 ){
setScreen("lost");
}
}
Upvotes: 0
Views: 11370
Reputation: 38795
var A = 14;
var J = 11;
var Q = 12;
var K = 13;
var cards = [A, "2", "3", "4", "5", "6", "7", "8", "9", "10", J, Q, K, A, "2", "3", "4", "5", "6", "7", "8", "9", "10", J, Q, K, A, "2", "3", "4", "5", "6", "7", "8", "9", "10", J, Q, K, A, "2", "3", "4", "5", "6", "7", "8", "9", "10", J, Q, K,];
A, J, Q, and K are numbers. Putting them in the array cards
doesn't make them into strings. you need to declare them in quotes (e.g. var A = "14"
).
You get the error on line 53 because you assign cards to the AI, some of which are numbers, and then try to output the values form the AI's hand... and at this point you still have numbers, not strings.
Upvotes: 2