Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple mistake somewhere

    Hello everyone,

    I just started trying to learn JavaScript and ran into a problem. If anyone could help me out it would be much appreciated
    Code:
    var cols:int = 4; // the number of columns in the card grid
    var rows:int = 4; // the number of rows in the card grid
    var totalCards:int = cols*rows; // 16 cards
    var matchesNeededToWin:int = totalCards * 0.5; // If there are 16 cards, the player needs to find 8 matches to clear
    var matchesMade:int = 0; // At the start, the player has not made any matches
    var cardW:int = 100; // each cards width is 100 pixels
    var cardH:int = 100;
    var aCards:Array; // We'll store all the cards we create in this Array
    var aGrid:Array; // This Array will keep track of the shuffled, dealt cards
    var aCardsFlipped:ArrayList; // This Array will store the two cards the player flips over
    var playerCanClick:boolean; // We'll use this flag to prevent the player from clicking buttons when we don't want him to
    var playerHasWon:boolean = false; // Store whether or not the player has won. This should start as false
    
    function Start () {
    playerCanClick = true;
    // Initialize the arrays as empty lists:
    aCards = new Array();
    aGrid = new Array();
    aCardsFlipped = new ArrayList();
    
    BuildDeck();
    
    var i : int;
    var j : int;
    
    for(i=0; i<rows; i++)
    {
    	aGrid[i] = new Array(); // Create a new, empty array at index i
    	
    	for(j=0; j<cols; j++)
    	{
    		aGrid[i] [j] = new Card();
    		}
    	}
    }
    
    
    
    
    function OnGUI () {
    GUILayout.BeginArea (Rect (0,0,Screen.width,Screen.height));
    BuildGrid();
    GUILayout.EndArea();
    print("building grid!");
    
    }
    class Card extends System.Object
    {
    	var isFaceUp:boolean = false;
    	var isMatched:boolean = false;
    	var img:String;
    	
    	function Card()
    	{
    		img = "CardTop";
    		}
    }
    
    function BuildGrid()
    {
    GUILayout.BeginVertical();
    GUILayout.FlexibleSpace();
    var i : int;
    var j : int;
    
    		for(i=0; i<rows; i++)
    	{
    		GUILayout.BeginHorizontal();
    		GUILayout.FlexibleSpace();
    		for(j=0; j<cols; j++)
    		{
    			var card:Object = aGrid[i][j];
    			if(GUILayout.Button(Resources.Load(card.img),
    				GUILayout.Width(cardW)))
    			{
    				Debug.Log(card.img);
    			}
    		}
    		GUILayout.FlexibleSpace();
    		GUILayout.EndHorizontal();
    	}
    	GUILayout.FlexibleSpace();
    	GUILayout.EndVertical();
    }
    
    function BuildDeck()
    {
    var totalSprites:int = 8; // Eight sprites nigga
    var card:Object; // card reference 
    var i:int;
    var j:int;
    
    	for(i=0; i<totalSprites; i++)
    	{
    		var aAllSprites:Array = [
    		
    		"Bruger",
    		"Eldromus",
    		"Griswold",
    	 	"Israfel",
    	 	"Kaelas",
         	"Pots", 
    	 	"Virgil",
    	 	"Wein"];
    		for(j=0; j<2; j++)
    		{
    			
    			var someNum:int = Random.Range(0, aAllSprites.length);
    			var randomSprite:String = aAllSprites[someNum];
    			
    			aAllSprites.RemoveAt(someNum);
    			
    			card = new Card("CardTop" + (i+1) + "Missing" + randomSprite);
    			aCards.Add(card);
    			
    			card = new Card("CardTop" + (i+1) + randomSprite);
    			aCards.Add(card);
    		}
    	}
    }
    Thanks for taking a look, I tried searching for the answer but every solution I found didn't help.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Javascript isn't the same as Java.
    Moving from Java forum to Javascript forum. You'll probably need to define what your actual problem is though.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Give us some help. We are not clairvoyant. What exactly is the problem?

    var i : int;
    var j : int;

    print("building grid!");

    Are you sure this is Javascript???? This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    uhh yeah thats nto javascript.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,516
    Thanks
    77
    Thanked 4,379 Times in 4,344 Posts
    That's actually JScript.Net, Microsoft's server-side language that's a variation on JavaScript to add strong typing.

    It won't run in a browser, only on the server. Or only as a standalone application.

    And this is a dead giveaway:
    Code:
    class Card extends System.Object
    System.Object is the .NET framework base object class.

    It's a "freak" language. Seldom used, even by MS-centric people. I suspect the only place Swahnsoon will get any help for this will be on the forums at www.asp.net -- and even there he'll only find a handful of people using the language.

    Swahnsoon: Are you intending this to be a standalone program? Then you'd be better off writing it in C#, where there are a lot more people using the language and a lot more help available. If you want to run it in a browser, then you need to stop using JScript.Net and use just ordinary JavaScript.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •