| |

How Did I Get from SAS to a Talking Monkey?

Today, I finished up a bonus Easter egg for the game, Aztech: Meet the Maya that you are taken to play when you click to see what Jose is thinking.  You can see a rough version of it here. This plays better on a desktop / laptop because iPad blocks the autoplay for sound, but when it’s packaged for the app store, that will work on the iPad as well.

This game uses several functions, all of which I wrote my little old self.

  1. Switches sound file played from English to Spanish
  2. Switches text from English to Spanish
  3. Takes you to the bonus game when you click on the sound bubble
  4. When the sound file ends, replaces the talking gif with a static image  and shows the arrow to continue.
  5. For each item on the screen, performs an action when clicked – anything from text describing it’s use to the Maya to a jumping and howling monkey. Also, removes that item name from the list of things to find, increases the number of found items by 1 and checks to see if all items are found.

There are probably some other things I forgot.

 

monkey

You might wonder how I got from SAS to here. Well, it all started with SAS macros. A macro is no more than a user-written function. When I was first exposed to this idea in graduate school back in the 1980s (yes, literally) my mind was blown! You mean, I could write my own functions?!

You might think this SAS macro that I wrote a couple of years ago

%macro sched(the_day,start1,finish1,teacher1,start2=0, finish2=0, teacher2=” “, start3=0,finish3=0, teacher3=” “);
if date_data = &the_day then do ;
if minutes > &start1 & minutes < &finish1 then tclass = &teacher1 ;
else if (&start2 > 0) & (minutes > &start2) & minutes < &finish2 then tclass = &teacher2 ;
else if &start3 > 0 & (minutes > &start3) & minutes < &finish3 then tclass = &teacher3 ;
end ;
%mend sched ;

doesn’t look like this JavaScript function

// Section to include sound. ;

function playJungleAudio(scene,langs) {
audio_e2 = new Audio();
audio_s2 = new Audio();

if(langs ===2){
audio_e2.src = "sounds/" + scene + "_eng.mp3";
audio_s2.src = "sounds/" + scene + "_sp.mp3";
if ($("#span_button").hasClass("noshow")) {
audio_e2.play();
} else {
audio_s2.play();
}
}
else {
audio_e2.src = "sounds/" + scene + ".mp3";
audio_e2.play();
}
}

If you look closely, though, these are identical in purpose and structure. Both are intended to package a set of statements that will then be executed when called. For both types of functions, SAS (macros) or JavaScript, parameters are optional. Both of these examples just happen to have parameters. Both have a defined start and stop.

In SAS it is

%macro macr0-name (parameters) ;

in JavaScript it is

function function-name(parameters) {

Both have a defined end, with SAS it is

%mend macroname ;

with JavaScript it is simply

}

 

Both are named functions (JavaScript also has anonymous functions), and when you call the function it executes.

It just so happens that both of these functions contain if-then – else statements.

To call the SAS macro, you give the macro name with a % in front of it, and include all the parameters in parentheses, separated by commas.

%sched(19292,790,840,”Elmo”,start2= 840, finish2=900, teacher2= “Bert”, start3=940,finish3=990, teacher3= “Snuffleupagus”);

To call the JavaScript function, you give the name, and include all parameters in parentheses, separated by commas.

 playJungleAudio("howler_monkey",1);

These parameters are then passed to the macro/ function and their values are plugged into the code between the beginning and end.

I have a lot more to say about this but it is getting close to 1 am and I have a plane to catch tomorrow so I’ll have to pick it up next time.

Speaking of  games – check out Making Camp, you can get it here for free. Play it and learn stuff because maturity is overrated.

wigwam

If you want to learn even more stuff, you can get a bilingual version of Making Camp for your iPad for only $1.99 and brush up on your Spanish like you always said you were going to do but didn’t

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *