Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-17-2007, 08:49 PM   #1
nightkarnation
Senior Member
 
Join Date: Apr 2007
Posts: 114
Default [AS2] Randomizing LoadVars content, what am i doing wrong?? 4 game!

Ok...this is a very small part of the complete code from a game im creating and i would really appreciate some help on this function:

Code:
	mcBtnComputer.onRelease = function() {
		//Goal: perform random computer selection
		var computerCheck:String = new String();
		//computerCheck string going to make sense later
		var tStats:Array = new Array();
		tStats[0] = "mojo";
		tStats[1] = "flavour";
		tStats[2] = "yeah";
		//randomize tNum from 0 to 2
		tNum = random(2);
		computerCheck = tStats[tNum];
		//computerCheck = mojo or flavour or yeah (up to here works fine)
		trace(computerCheck);
		//loadVars as tGirls2 (working fine)
		var tGirls2:LoadVars = new LoadVars();
		tGirls2.load("pics/tGirl"+player2Randomizer+".txt");
		tGirls2.onLoad = function() {
			//HERE I NEED HELP: if i try: computerSelection = tGirls2.mojo; <--works fine
			//but if i try as below its not working and i need it like this because i want to
			//randomize it
			computerSelection = Number(tGirls2.computerCheck);
			//computerSelection = NAN ... why?? remember before on 
			//trace computerCheck was displaying or mojo or flavour or yeah
			trace(computerSelection);
		};
	};
the txtfile has 3 variables
&mojo = 10&
&flavour = 8&
&yeah = 6&
nightkarnation is offline   Reply With Quote
Old 04-18-2007, 02:51 AM   #2
jcodec
UI Engineer
 
Join Date: Apr 2007
Location: Hollywood, CA, USA
Posts: 79
Default Remove Number conversion to debug

Unfortunately, the amount of source you provided does not allow me to completely debug your application. You may have a problem with your text files, or with variables declared outside the scope of this function (computercheck). However, there is one thing you can do to help your debugging. trace thirls2.computercheck (without the Number conversion) and see what it is. When a Number is traced it can only show a string representation of a Number, undefined or null. Any other value will come up as NaN. Trace the value before conversion and see what it is. That may give you some clue as to what's wrong.
jcodec is offline   Reply With Quote
Old 04-18-2007, 04:07 AM   #3
nightkarnation
Senior Member
 
Join Date: Apr 2007
Posts: 114
Default

Hey J! first of all thanx for replying...I tried what u suggested and its giving undefined, but anyway cant seem to address the issue...

im guessing the problem is on this line:

Code:
computerSelection = Number(tGirls2.computerCheck);
i've tried:

Code:
computerSelection = Number(tGirls2[computerCheck]);
computerSelection = (tGirls2[computerCheck]);
computerSelection = Number(tGirls2.computerCheck);
Still not working...still getting undefined when i try this first and then the line above :

Code:
trace(tGirls2[computerCheck]);
trace(tGirls2.computerCheck);
trace(String(tGirls2[computerCheck]));
trace(String(tGirls2.computerCheck));
But...if i try: (is giving me the correct amount of letters on the TXT file!!, and not the amount of undefined) (????)

Code:
trace(computerCheck.length);
nightkarnation is offline   Reply With Quote
Old 04-18-2007, 04:42 AM   #4
nightkarnation
Senior Member
 
Join Date: Apr 2007
Posts: 114
Default

J!! i realized what was the problem. This is the correct code:

Code:
		computerCheck = (tStats)[tNum];
		trace(computerCheck);
Output: mojo, flavour or yeah

Thanks for your help it was very helpfull!
nightkarnation is offline   Reply With Quote
Old 04-25-2007, 06:21 PM   #5
jcodec
UI Engineer
 
Join Date: Apr 2007
Location: Hollywood, CA, USA
Posts: 79
Default No problem

Glad to help!

The cornerstone of good programming is good debugging.
jcodec is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
single preloader(s) for DB content? jpmad4it ActionScript 1.0 (and below) 9 06-03-2005 12:25 AM
[AS2] Similar Game to "Snake" RENEE0 Gaming and Game Development 3 05-25-2005 12:22 PM
Augh. Too many ways to skin a cat. (game design q's) beau Gaming and Game Development 0 01-14-2005 07:08 PM
[AS1] Swapdepth using txt files and dynamic content for game. superbnerb Gaming and Game Development 3 09-22-2004 07:27 PM
XML and menutext content sanderH Components 1 07-21-2004 06:01 PM


All times are GMT. The time now is 04:19 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.