Implementation of array.

29 10 2008

We have now decided that we are going to use an array within our organism to only store the last email that has been entered by a user, and this will be the food that annie ‘goes off’ to find and eat. Her happiness will go down because she has to go find the food but also up because she has got to eat so they both cancel each other out as she is surviving and wont get too emotional about it wither way.

What we have written is very simple to store the email:

emails = new Array();

emails[0] = food;

‘food’ is a variable we created very early on in the project and basically it is the value of whatever the user has entered i.e the Email when they use the onRelease function (Clicking the feed me button)

 

<script type=”text/javascript”>
var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));
</script>
<script type=”text/javascript”>
try {
var pageTracker = _gat._getTracker(“UA-11563787-1″);
pageTracker._trackPageview();
} catch(err) {}</script>





Flash Arrays Research

29 10 2008
This is just a little bit of research for creating the Arrays, these codes have been trie and tested and are ready to be implemented into our script when we get to that stage.
 
Example 1:
E-mails = new Array();
E-mails[0] = “example@hotmail.co.uk”;
E-mails[1] = “example2@hotmail.co.uk”;
E-mails[2] = example3@hotmail.co.uk;
 
Example 2:
 
E-mails = new Array(“example@hotmail.co.uk”,“example2@hotmail.co.uk”,“example3@hotmail.co.uk”);
 
Example 3:
 
E-mails = new Array();
E-mails["hotmail"] = example@hotmail.co.uk;
E-mails["gmail"] = “example@gmail.co.uk”;
E-mails["yahoo"] = example@yahoo.co.uk”;
I think that for our Organism we will use either example 1 or example 3, example 1 would be good for simplicity and understanding of code but example 3 would be good if we needed to get a little more complex with the email system as it uses larger amounts of detail. 
 

 

 




UPDATE: Organis, what it does….

29 10 2008

Just a quick update on what we have accomplished.

At this stage our Organism:

  • Moves around its petri dish.
  • Moves at different speeds.
  • Has its own emotions based on how well its being cared for.
  • Eats
  • Lives (constant moving)
  • Gets unhappy when not fed after a certain period of time (Dynamic and Constantly being updated real time.
  • Sleeps (in real time)
  • Dies

Taking on Artificial Intelligence piece by piece. ^^





Slight Change of Idea for Food Search…

29 10 2008

Changing A.I behaviour…

It seems that with deadlines looming it may be a bit of a tall order to learn how to link databases with php as we have only ever done it in asp and can’t seem to find an efficient way to implement that knowledge into our organism yet….sooooo..we are going to now create an array within the original flash document to store all entered emails that are valid which the organism can search into later on (in conjunction with the timer function we are working on at the moment).

This array will be where ‘Annie’ goes to, to look  for its food once it gets annoyed of waiting for someone else to do it. We will assign index numbers to each individual array entry for the emails entered, so that we can write some script for Annie to pick a random email i.e a random number from the list.

Hopefully this won’t cause us too much of a problem.





Linking Between PHP and AS2

29 10 2008

This morning I was looking through countless tutorials to get a php page to extract variables from Actionscript, finally i have found a working example which will be extremely simple to manipulate for our organism and also make it a little bit better once we have introduced an array or database of some kind.

The example code:

ActionScript:

Btn.onPress = function ()
{
mail_lv = new LoadVars();
mail_lv.dummy1 = “”;
mail_lv.subject = “SSEN CLAN Membership”;
mail_lv.message = “email_addy”;
mail_lv.skin = “skin_result”;
mail_lv.pw = “password”;
mail_lv.fname = “first_name”;
mail_lv.lname = “last_name”;
mail_lv.dummy2 = “”;
mail_lv.onLoad = function ()
{
trace(“Sent successfully…”);
trace(“mail_lv.subject = ” + mail_lv.subject);
trace(“mail_lv.message = ” + mail_lv.message);
}
mail_lv.send(“
http://localhost/PHP/mail3.php“, “_blank”);
// mail_lv.send(“
http://localhost/PHP/mail3.php“, mail_lv, “POST”);
// loadVariables (“mail.php3″,0,”POST”);
// gotoAndStop (“pg3″)
}

and the PHP:

<?php
if (isset($_POST['subject']))
$subject = $_POST['subject'];

if (isset($_POST['message']))
$message = $_POST['message'];

echo(“subject = $subject<BR>”);
echo(“message = $message<BR>”);
mail(“dan.netherton@students.plymouth.ac.uk“, $subject, $message);
?>

Next thing to do will be to look at linking Databases (MS Access ones) with the PHP pages to retrieve and update records hopefully…..





Countdown Timer Success!

29 10 2008

EXTRACT TAKEN FROM   -  http://livenickmarshall.wordpress.com:

“Today we added a timer function, the aim with this is that after 10 minutes of not being fed, the organism will go look for food on its own but also become a bit unhappier. The code below demonstrates a simple countdown function with an embedded if statement.

 countdown = function(){
    timer –; 
 if(timer==0){
       timer = 300;
    happiness = happiness – 10;
 }
 trace(timer);
 trace (happiness);
} “





Timer Function for ‘Sleep’…

23 10 2008

Today we also created wrote some script in order to control the behaviour of Annie in accordance to the time. At the moment it is working between the hours of 19:00 and 0:00 this is the period which at the moment, annie sleeps in. Therefore she is unable to be fed. Also when Annie is sleeping she acquires a lower alpha level.

Code:

timedate = new Date();
var clockH = timedate.getHours();
var clockM = timedate.getMinutes();

trace(clockH);

if (clockH >= 19 and clockH <= 23){
speed = 0;
happiness = 50;
_root.cell._alpha=20;
}

OK…you can see how easy it was to influence this behaviour with this small piece of code, but then again this is only from an hours point of view. Soon we wish to be able to provide more detail of sleep patterns by using minutes and even seconds to control her. Also when she wakes back up again her happiness level returns to a neutral state, much like when we up and feel a lot calmer than when we went to bed (in most cases).

When we get the minutes working they will influence Annie’s eating patterns that she decides herself! After a period of 10 minutes if she hasn’t been fed she will become a little adventurous and go out searching for food, and by ‘go out’ i mean go into her previously typed email entries and scoff on some of those. She will not gain any happiness from this as she is doing it herself (lazy) but it will keep her alive that little bit longer.





Emotions : Code and Concept

23 10 2008

Today me and nick managed to create and manipulate some code to form the basis of annies changing state of emotions. The code that we have come up with is this:

else if (happiness >= 1 and happiness <= 10){
speed = 2;
_root.cell._alpha=10;
myColor.setRGB(0×333333);
}

else if (happiness >= 11 and happiness <= 20){
speed = 4
_root.cell._alpha=20;
myColor.setRGB(0×000033);
}

else if (happiness >= 21 and happiness <= 30){
speed = 6
_root.cell._alpha=30;
myColor.setRGB(0×003366);
}

This isnt all of the code that we have used but you get the idea. Oh and the maximum happieness annie can be is at 100. (Idea of incorporating insanity after this integer?….hmmmm..?)

Happiness of the organism controls these things:

-The speed in which it moves around the petri-dish

-The colour of the organism (Max.Happy = Green Max.Unhappy = Black)

- The alpha (opacity) of the organism

The organism is now taking on almost lifelike characteristics! ^^





Moving on…….

22 10 2008

The thing we are going to do next is get a little deeper into the code design (ActionScript) we are going to attempt to get the user to type in their data in this case and email and then try and store that data into a variable, this variable will be later used in conjunction with php and a database. We are also going to look at changing graphical properties of things from within the actionscript itself in relation to mood of the organism……





i-DAT Organism code:

16 10 2008

Flash

// first we make a new loadvars object to hold the variables that are being loaded from the php file
myData = new LoadVars();
//this is the part where we execute the function that handles the loaded data
myData.onLoad = function(){
 VariableLoad
();//call the function
};
//here we load in the php file, make sure you set the right path to your file
myData.load(”http://localhost/index.php”);

//this is the function that handles the data.
//the variables now sorta live in the loadVars object we set named myData
//So we can call em like myData.myVariableInthePhpPrintedString
//just look at the script and whatch carefully how its being called and it should become clear to ya. 
VariableLoad = function(){
 txtBox1.text = myData.textbData1;
 txtBox2.text = myData.textbData2;
 txtBox3.text = myData.textbData3;
};

PHP

<?php
/*Getting the variable ‘toPHP’ sent from flash using the ‘POST’ method*/
$fromFlash = $_POST['toPHP'];
/*Encrypting the $fromFlash and storing it as $encrypted*/
$encrypted = md5($fromFlash);
/*getting ready to send a variable to flash named toFlash using ‘&variableName=’*/
$toFlash = “&toFlash=”;
/*Asigning the encrypted variable to $toFlash AFTER the ‘=’*/
$toFlash .= $encrypted;
/*echoing out $toFlash so that flash can read it*/
echo $toFlash;
?>