| |

SAS taught me how to make best-selling games

I’m going to be speaking at SAS Global Forum about the places you can go starting your career with SAS, for example …

If you know anything about SAS, you might think from the title that I used my mad data analysis skills to figure out what works and what doesn’t for games. While that is somewhat true, it is not at all what this post is  about.  In fact, learning SAS first helped me a lot when it came to actually MAKING games. No, there is not a lick of SAS code in our games, but the concepts and ideas came to me fairly easily because of my experience using SAS.

(If you read this and start to post a comment saying I could have learned everything here from Python or C or whatever your favorite language is, I am sure you are right. The fact is, though, I didn’t. )

Let me give you an example:

The object of the game is to match as many synonyms as possible in one minute. This is what has to happen:

  1. On loading the page, randomly select a word to display on the screen, start the timer and music
  2. Show the number of seconds on the page, going down every second
  3. On the page, show 7 other words, 3 that are synonyms and 3 that are not synonyms, making sure that the correct and incorrect words show up in random order.
  4. If the player drags a correct word into the box, it turns green and adds 1 point to the score.
  5. If the player drags an incorrect word, the box turns red
  6. If all three choice boxes are filled, all the boxes are cleared and a new word and choice boxes are shown
  7. When the time is up, if the player has a perfect score, show a happy image and appropriate text.
  8. If the player doesn’t have a perfect score, show a less happy image and appropriate text.
  9. When time is up, show a button the player can click to play again.

thumbs up for getting a perfect score

What in the heck does all of that have to do with SAS? It’s all written in JavaScript, the reason for that is a post for another day, but let’s look at some code:

<script type="text/javascript">
    $(document).ready(function () {

        //Timer script ;
        var time = 60000;
        var timer ;

This first bit just starts a script, and the beginning of a function that will execute when the document is ready. That is, I don’t want JavaScript to try acting on elements that aren’t loaded yet. My first exposure to writing functions was in the 1980s. It was a very significant event. I swear, I even remember the cramped graduate assistant office at the University of California, Riverside where I read my first book of SAS macros. I think it was a book of macros written by users. This is how we distributed things before the Internet. I thought the idea of writing my own functions was the coolest thing I had ever heard.

Now, for the timer. Everyone knows what a variable is, or you do if you did anything with any language. Here, I am initializing the time to 60,000 milliseconds. Initializing a variable, another basic idea I learned from SAS. I’m going to use that other variable, timer, later to execute the myTimer function. Just wait.

//Timer script ;
function myTimer() {
    if (time > 0) {
        var nowTime = time/1000 ;
        document.getElementById("timer").innerText = nowTime  ;
        time = time - 1000;
    }
    else if (time <= 0) {
        document.getElementById("timer").innerText = "0";
        clearInterval(timer);

            $("#form1").hide();
            //IF ALL OF YOUR ANSWERS WERE CORRECT ;
            if (correct === boxmove)
            {
                $("#correct").text("PERFECT! You answered " + thesepts + " correctly.");
                $("#correcto").slideDown('slow');
                playAudioLocal("../../sounds/correct1");

            }
            else  {
                $("#wrongo").show();
                $("#incorrect").text("You answered " + thesepts + " correctly.").slideDown('slow');
                playAudioLocal("../../sounds/flute");
            }
            $("#redo").show();

    }

Except for a few specific details, everything in the script above, I learned or improved from using SAS.

IF- THEN-DO-END   – instead of DO and END , I have an opening { and a closing }  but it’s the same thing.

If the time is greater than 0, the variable nowTime is going to be set to time divided by 1,000 since most people would prefer to see their time in seconds rather than milliseconds. By the way, nowTime is a local variable, defined within  a function. Local variables is another idea I first learned from SAS macros, thank you very much. The text of the element in the page named ‘timer’ is now set to whatever the number of seconds remaining is (nowTime). We deduct another milliseconds from time.

ELSE – DO is another common SAS bit of code . If there is no time left, do all of this stuff, e.g., set the time value to 0, stop calling the timer function.

You can have nested IF-THEN-DO code in SAS, as I do here in my JavaScript.

While SAS didn’t introduce me to text functions, it’s where I learned a lot of them. Here, we  have a JavaScript text function where I’m concatenating a string with a variable and then another string.

So, we’ve knocked off numbers 2, 7, 8 and 9. All of the showing and hiding elements had nothing to do with SAS . That part was straight jQuery but that was the easy part. Actually, this whole part was pretty easy. A few tricky bits show up later on.  Maybe I’ll get to them in my next post. While you are waiting with bated breath …..

Check out Making Camp because maturity is overrated.  Learn Ojibwe history, brush up on your math skills and build out your virtual wigwam.

wigwam

 

Similar Posts

One Comment

Leave a Reply

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