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");
}
}
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");
}
}
Share
Improve this question
edited Mar 30, 2017 at 3:22
treves tucker
asked Mar 30, 2017 at 2:33
treves tuckertreves tucker
11 gold badge1 silver badge1 bronze badge
1
- 1 Language? Might be good as a tag... I'm assuming JavaScript / JQuery. – ProgrammingLlama Commented Mar 30, 2017 at 2:35
1 Answer
Reset to default 2var 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745347954a4623650.html
评论列表(0条)