我对这个代码的问题是一个名为war的纸牌游戏,错误说" Line:53:setText()文本参数值(undefined)不是一个uistring" 我尝试用一种全新的方式编辑代码,并且一直在说它。
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");
}
}
答案 0 :(得分:2)
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和K是数字。将它们放入数组cards
并不会将它们变成字符串。你需要用引号声明它们(例如var A = "14"
)。
您在第53行收到错误,因为您将卡分配给AI,其中一些是数字,然后尝试从AI手中输出值...此时您仍然有数字,而不是字符串。