vliegenderidder Posted January 10, 2015 Share Posted January 10, 2015 Hi there, I'm building a game currently but I have a small problem with keeping the score. Basically I have an textfield that gets a random word input, then if someone clicks on the field or symbol containing the field then I want to check the random word input, if it's a correct word I want to update score textfield, if it's incorrect I want to update errors textfield. For this I am using an if/else construction, the problem I have with it is that in my game every click only goes either in the if statement or if I change code then only the else, but it's not checking symbol for symbol, every time I click to see if it's an correct word or not. Here is the code I am using on the symbol.click symbol. My question is, am I doing anything wrong in the if/else statements or are my variable calling methods wrong. I have source files on request._______________________________symbol.click:var y = sym.getVariable("lijst");var x = "bommen"; // if variables are a match then update score with 1if (sym.getVariable("x") == sym.getVariable("y")){var score3 = sym.getComposition().getStage().getVariable("score1"); score3= score3 +=1;sym.getComposition().getStage().$ ("scoreTxt").html(score3);sym.getComposition().getStage().setVariable("score1", score3);} // else update error textfield with 1else {var fouten= sym.getComposition().getStage().getVariable("fouten1"); fouten= fouten +=1;sym.getComposition().getStage().$ ("hpTxt").html(fouten);sym.getComposition().getStage().setVariable("fouten1", fouten);} ___________________________________________symbol.creationCompletevar words = ['bommen','dammen','kanonnen','dollen','bomen','feesten','lampen','voeten',];var lijst = words[Math.floor(Math.random() * words.length)];sym.$("dynamicText").html(lijst);____________________________________________//And my stage: stage.creationComplete// some different variables declarationssym.setVariable("score1", 0);sym.setVariable("fouten1", 0)//var game = sym.getComposition().getStage();var cirkels = [];var test1 = "bommen";var score2 = sym.getComposition().getStage().getVariable("score1"); var fouten = sym.getComposition().getStage().getVariable("fouten1");var cirkelStart = {x:180,y:190};var cirkelSpacing = {x:170,y:170}; function init(){ initPlayer(); spawnCirkels();}//this is for score and error updating function initPlayer(){sym.$("scoreTxt").html(score2);sym.$("hpTxt").html(fouten); }// create symbols on a gridfunction spawnCirkels(){var cirkel;var el; var i;var xPos = cirkelStart.x;var yPos = cirkelStart.y;var col = 0;for(i = 0;i < 15;i++){ cirkel = sym.createChildSymbol("Cirkel", "Stage");cirkel.play(Math.random() * 1000);cirkels.push(cirkel);el = cirkel.getSymbolElement();el.css({"position":"absolute", "top":yPos + "px", "left":xPos + "px"}); xPos += cirkelSpacing.x; col++; if(col === 5){col = 0;yPos += cirkelSpacing.y;xPos = cirkelStart.x;}} } init(); ___________________________________________________If anyone sees what I am doing wrong let me know! Thanks for your help anyway! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.