Be a Supporter!
Response to: Check range within math.random? Posted February 2nd, 2014 in Game Development

This should do the trick:

if (aiNumber <= 7)
{
	aiAttack();
}
else if (aiNumber <= 9)
{
	aiMagic();
}
else
{
	aiHeal();
}
Response to: What percentage of people. . . Posted January 20th, 2014 in Game Development

At 1/19/14 01:30 PM, MintPaw wrote: Well my artist accidently checked "requires sign in" on our last. So it's been up about a week with only signed in users being able to play, just wondering on about how much we missed out on.

More than 20% of the users should be logged in I think, this is only a fast guess though.
(My recent game has 1487 views (there are less users who played it than views),
and 286 users unlocked the level 1 medal (you have to be logged in to get the medal), players who stopped playing before finishing lv 1 are not accounted for, you may get a more exact result if you find a game where you immadiately get a medal)

Hope this helps a bit.

Response to: Save File Browser Component Posted January 15th, 2014 in Game Development

At 1/15/14 05:31 PM, kkots wrote: If you are using connector component, you can just go to component inspector and set debugMode field to OFF.
But in manual connection you need to put this line before API.connect()

API.debugMode=API.RELEASE_MODE;

Also, Newgrounds was not updating the SWF for me.
I had to go to File-->Publish Settings and set the SWF location somewhere else.
Then I had to go to Project System, delete the old SWF, upload the new SWF from that location.
When I wanted to update again I had to again change file location (or just add a number index to the end of the SWF file name), again, delete file, re-upload.
Also, after every re-upload, I had to delete cache in browser.
Also, after every re-upload, Newgrounds changes dimensions to 640x480.

So I got it working without errors in my test project. It is a matter of making slight fixes, re-uploading and checking if it works.
Rinse and repeat until it works.

I found the cause of the security error.
http://forums.adobe.com/message/3452199
The calls to save must be triggered by MouseClicks etc., I always tried to save at the end of the levels.

Thanks again for the help, I'm glad I got this sorted out.

Response to: Save File Browser Component Posted January 15th, 2014 in Game Development

Okay, I changed my code to only query once, load if needed and save (multiple times) afterwards.
Working fine in DebugMode, thanks for your help so far.

About my security error: I think I just need to use different file names for different users as they are all in the same folder?
I'll try if that' the problem and report back as soon as I know more.

Response to: Save File Browser Component Posted January 15th, 2014 in Game Development

At 1/15/14 03:42 PM, kkots wrote: I assume you are going to save and load multiple times during a single game session? If no, then you will not need to execute query every time you want to save. You can save as many times as you want, and after loading.
You only can't LOAD after SAVING. You can save after loading just fine, and as many times as you want.
There is no need to execute query before saving! You can save right away!

If you have a platformer, for example, you will only need to load the game once, and save it when player achieves something worthy of saving.
Maybe your game is going to load a save more than once during a single game session? But that makes no sense if each player has only one file.

Hmm, you're right, i'll try it.
I have the next problem though, it works fine in API.DebugMode, but in API.ReleaseMode mode I get a userNot logged in Error. (naturally, since I didn't run it on newgrounds.)
So I uploded it to my projects page and now I get a security error.

The API output:

Connecting to the Newgrounds API Gateway...
----- Platformer -----
Medal: Test Medal		(locked, 0pts, Easy)
Medal: Level 1		(locked, 0pts, Moderate)
Medal: Level 2		(locked, 0pts, Moderate)
Medal: Level 3		(locked, 0pts, Moderate)
Medal: Level 4		(locked, 0pts, Moderate)
Medal: Level 5		(locked, 0pts, Moderate)
Medal: Nohit 1		(locked, 0pts, Moderate)
Medal: Nohit 2		(locked, 0pts, Challenging)
Medal: Nohit 3		(locked, 0pts, Challenging)
Medal: Nohit 4		(locked, 0pts, Challenging)
Medal: Nohit 5		(locked, 0pts, Challenging)
Medal: Master		(locked, 0pts, Difficult)
12 medals initialized.
0 scoreboards initialized.
SaveGroup: saves  Keys:   Ratings: 
1 save group initialized.
Connection complete!
Unable to load data:
[SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048"]
Error when sending command:
SecurityError: Error #2176
Error saving file "save":
unknownError

I invited you as BetaTester if you want to see for yourself.

Response to: Save File Browser Component Posted January 15th, 2014 in Game Development

At 1/15/14 03:03 PM, kkots wrote: Sorry, this info is WRONG.
When you update a save file (by update I mean save a file which you got from query) its key remains UNCHANGED.
However, after you save a file, you may not load it.

Let's consider this some sort of a rule.
No matter when, and no matter how large is the time interval between saving and loading is, you can't load a file after saving it, unless you execute query again and re-obtain it.

I can't explain why.

Thank you very much, my problem is solved now.
I thought you had to run the query once at the beginning and could use the saveFile afterwards as you wanted.

I now changed my testCode to this:

import com.newgrounds.*;

var saveFile:SaveFile;
var myData:Object = "test";
var fileRequest:String = "none";

//test saving as soon as connected
API.addEventListener(APIEvent.API_CONNECTED, save);
API.connect(this, "<id>", "<key>");

function executeQuery(e:APIEvent = null):void
{
	var query:SaveQuery = API.createSaveQuery("saveGroup");
	query.addCondition(SaveQuery.AUTHOR_ID, SaveQuery.OPERATOR_EQUAL, API.userId);
	query.addEventListener(APIEvent.QUERY_COMPLETE, queryComplete);
	query.execute();
}

function queryComplete(event:APIEvent):void
{
	if (event.data.files.length == 0)
	{
		saveFile = API.createSaveFile("saveGroup");
		saveFile.name = "saveFile";
	}
	else
	{
		saveFile = event.data.files[0];
		trace("file found");
	}
	
	switch(fileRequest)
	{
		case "load":
		{
			saveFile.addEventListener(APIEvent.FILE_LOADED, onLoaded);
			saveFile.load();
			break;
		}
		case "save":
		{
			saveFile.addEventListener(APIEvent.FILE_SAVED, onSaved);
			saveFile.data = myData;
			saveFile.save();
			break;
		}
	}
	fileRequest = "none";
}

function save(e:* = null):void
{
	fileRequest = "save";
	executeQuery();
}

function load(e:* = null):void
{
	fileRequest = "load";
	executeQuery();
}

function onSaved(e:APIEvent):void
{
	if(e.success)
	{
		trace("'" + e.data.data + "' saved");
		
		//test loading after saving was successful
		load();
	}
	else trace(e.error);
}

function onLoaded(e:APIEvent):void
{
	if(e.success)
	{
		myData = saveFile.data;
		trace("'" + myData + "' loaded");
	}
	else trace(e.error);
}

I will use analog code in my game.

Response to: Save File Browser Component Posted January 15th, 2014 in Game Development

Hi,
I can't get my loading/saving with the Newgrounds API to work, I read through a few topics in this forum, google wasn't of much help and I still can't find my mistake.
You guys know how it works, so I'd like to ask you if you could help me finding it.
Help is greatly appreciated as this is the last missing piece to finishing my first flash game.

I always get a "badFile" error when trying to load:

This is what my code looks like:
(AS3, first frame of my otherwise empty Adobe Flash Professional CS 6-project)

import com.newgrounds.*;

var saveFile:SaveFile;
var myData:Object = "test";

API.addEventListener(APIEvent.API_CONNECTED, executeQuery);
API.connect(this, "<myApiId>", "<myEncryptionKey>");  //imagine my project's id&key here

function executeQuery(e:APIEvent):void
{
	var query:SaveQuery = API.createSaveQuery("saveGroup");
	query.addCondition(SaveQuery.AUTHOR_ID, SaveQuery.OPERATOR_EQUAL, API.userId);
	query.addEventListener(APIEvent.QUERY_COMPLETE, queryComplete);
	query.execute();
}

function queryComplete(event:APIEvent):void
{
	if (event.data.files.length == 0)
	{
		saveFile = API.createSaveFile("saveGroup");
		saveFile.name = "saveFile";
	}
	else
	{
		saveFile = event.data.files[0];
		trace("file found");
	}
	saveFile.addEventListener(APIEvent.FILE_SAVED, onSaved);
	saveFile.addEventListener(APIEvent.FILE_LOADED, onLoaded);
	
	//test saving after saveFile initialisation
	saveFile.data = myData;
	saveFile.save();
}

function onSaved(e:APIEvent):void
{
	if(e.success)
	{
		trace("'" + e.data.data + "' saved");
		
		//test loading after saving was successful
		saveFile.load();
	}
	else trace(e.error);
}

function onLoaded(e:APIEvent):void
{
	if(e.success)
	{
		myData = saveFile.data;
		trace("'" + myData + "' loaded");
	}
	else trace(e.error);
}

My output looks like this:

[Newgrounds API] :: ====== Newgrounds API v3.2 AS3 ======
[Newgrounds API] :: Connecting to the Newgrounds API Gateway...
[Newgrounds API] :: ----- SaveAndLoad -----
[Newgrounds API] :: 0 medals initialized.
[Newgrounds API] :: 0 scoreboards initialized.
[Newgrounds API] :: SaveGroup: saveFiles  Keys:   Ratings: 
[Newgrounds API] :: SaveGroup: saveGroup  Keys:   Ratings: 
[Newgrounds API] :: 2 save groups initialized.
[Newgrounds API] :: Connection complete!
file found
[Newgrounds API] :: File "saveFile" saved!
'test' saved
Error when opening the URL 'http://apifiles.ngfiles.com/savedata/35000/35364/904/564000/file_saveFile_564708.zlib&random=0.5083370530046523'
[Newgrounds API] :: Unable to load data:
[Newgrounds API] :: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream-Fehler. URL: http://apifiles.ngfiles.com/savedata/35000/35364/904/564000/file_saveFile_564708.zlib&random=0.5083370530046523"]
badFile

Thanks for your help.