Wednesday, 16 April 2014

Working Processes: Creating the Game - Reading the Note, Vending Machine Code and Splice Issues

Today, I made it so that the note [on the table] can be read, if you have the lightbulb inserted and are wearing your glasses (otherwise the text is blurred).

I have also introduced the ability to add the order code, found from the notebook, into the vending machine. Since adding the order code to the vending machine was through buttons on the vending machine, this meant that I would have to convert each button into a movieclip. To avoid doing this I created a invisible symbol and place it on top of each button. This way, I didn't need to create a new symbol for each button. The symbols could be copied and pasted, and thus reused with different instance names.

I created the following code for the buttons.

// ---------Characters on 5 - Remove buttons ---------
function vendingTextCountListener(event:Event) {
    if (vendingMachine_txt.text.length>=5) {
        trace("No Room Left");
        removeVBtnListeners();
        receiptBooleanCheck();
        stage.removeEventListener(Event.ENTER_FRAME, vendingTextCountListener);
    }
}
// ---------Characters on 0 - Add buttons ---------
function vendingTextCountReset(event:Event) {
    if (vendingMachine_txt.text.length==0) {
        trace("Characters Reset | Room to type");
        addVBtnListeners();
        stage.removeEventListener(Event.ENTER_FRAME, vendingTextCountReset);
    }
}
// ---------Start Again---------
VbtnCANCEL.addEventListener(MouseEvent.CLICK,vBtnCancel);
function vBtnCancel(ev:MouseEvent):void {
    vendingMachine_txt.text=("");
    stage.addEventListener(Event.ENTER_FRAME, vendingTextCountReset);
    stage.addEventListener(Event.ENTER_FRAME, vendingTextCountListener);
}
// ---------Add / Remove functions---------
function addVBtnListeners():void {
    VbtnA.addEventListener(MouseEvent.CLICK,vBtnAListener);
    VbtnB.addEventListener(MouseEvent.CLICK,vBtnBListener);
    VbtnC.addEventListener(MouseEvent.CLICK,vBtnCListener);
    VbtnD.addEventListener(MouseEvent.CLICK,vBtnDListener);
    VbtnE.addEventListener(MouseEvent.CLICK,vBtnEListener);
    VbtnF.addEventListener(MouseEvent.CLICK,vBtnFListener);
    VbtnG.addEventListener(MouseEvent.CLICK,vBtnGListener);
    VbtnH.addEventListener(MouseEvent.CLICK,vBtnHListener);
    VbtnI.addEventListener(MouseEvent.CLICK,vBtnIListener);
    Vbtn1.addEventListener(MouseEvent.CLICK,vBtn1Listener);
    Vbtn2.addEventListener(MouseEvent.CLICK,vBtn2Listener);
    Vbtn3.addEventListener(MouseEvent.CLICK,vBtn3Listener);
    Vbtn4.addEventListener(MouseEvent.CLICK,vBtn4Listener);
    Vbtn5.addEventListener(MouseEvent.CLICK,vBtn5Listener);
    Vbtn6.addEventListener(MouseEvent.CLICK,vBtn6Listener);
    Vbtn7.addEventListener(MouseEvent.CLICK,vBtn7Listener);
    Vbtn8.addEventListener(MouseEvent.CLICK,vBtn8Listener);
    Vbtn9.addEventListener(MouseEvent.CLICK,vBtn9Listener);
    Vbtn0.addEventListener(MouseEvent.CLICK,vBtn0Listener);
    VbtnS.addEventListener(MouseEvent.CLICK,vBtnSListener);
}
function removeVBtnListeners():void {
    VbtnA.removeEventListener(MouseEvent.CLICK,vBtnAListener);
    VbtnB.removeEventListener(MouseEvent.CLICK,vBtnBListener);
    VbtnC.removeEventListener(MouseEvent.CLICK,vBtnCListener);
    VbtnD.removeEventListener(MouseEvent.CLICK,vBtnDListener);
    VbtnE.removeEventListener(MouseEvent.CLICK,vBtnEListener);
    VbtnF.removeEventListener(MouseEvent.CLICK,vBtnFListener);
    VbtnG.removeEventListener(MouseEvent.CLICK,vBtnGListener);
    VbtnH.removeEventListener(MouseEvent.CLICK,vBtnHListener);
    VbtnI.removeEventListener(MouseEvent.CLICK,vBtnIListener);
    Vbtn1.removeEventListener(MouseEvent.CLICK,vBtn1Listener);
    Vbtn2.removeEventListener(MouseEvent.CLICK,vBtn2Listener);
    Vbtn3.removeEventListener(MouseEvent.CLICK,vBtn3Listener);
    Vbtn4.removeEventListener(MouseEvent.CLICK,vBtn4Listener);
    Vbtn5.removeEventListener(MouseEvent.CLICK,vBtn5Listener);
    Vbtn6.removeEventListener(MouseEvent.CLICK,vBtn6Listener);
    Vbtn7.removeEventListener(MouseEvent.CLICK,vBtn7Listener);
    Vbtn8.removeEventListener(MouseEvent.CLICK,vBtn8Listener);
    Vbtn9.removeEventListener(MouseEvent.CLICK,vBtn9Listener);
    Vbtn0.removeEventListener(MouseEvent.CLICK,vBtn0Listener);
    VbtnS.removeEventListener(MouseEvent.CLICK,vBtnSListener);
}
// ---------The button functions---------
function vBtnAListener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"A");
}
function vBtnBListener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"B");
}
function vBtnCListener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"C");
}
function vBtnDListener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"D");
}
function vBtnEListener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"E");
}
function vBtnFListener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"F");
}
function vBtnGListener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"G");
}
function vBtnHListener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"H");
}
function vBtnIListener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"I");
}
function vBtn1Listener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"1");
}
function vBtn2Listener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"2");
}
function vBtn3Listener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"3");
}
function vBtn4Listener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"4");
}
function vBtn5Listener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"5");
}
function vBtn6Listener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"6");
}
function vBtn7Listener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"7");
}
function vBtn8Listener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"8");
}
function vBtn9Listener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"9");
}
function vBtn0Listener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"0");
}
function vBtnSListener(ev:MouseEvent):void {
    vendingMachine_txt.text=(vendingMachine_txt.text+"*");
}

I scripted this so not only would the user be able to to use each number and letter of the vending machine, but also so that if they had gone over 5 characters, the eventlistener would be removed so they weren't able to continue.
The cancel feature (the red c), was made so that users would be able to delete the characters they typed in if they wanted to start again.


The entering of the buttons were applied to a new frame, so that the user had to zoom into the buttons before proceeding.

There were also issues with the Splice feature which I needed to address.

When testing the game myself, each time I had plugged in the lightbulb and went to view the drawers to collect the key, upon pressing the back button - they key would automatically be removed from my inventory. This created a lot of confusion as I didn't know why this was the case, since to my knowledge, the code was flawless.

What I had not realised is that the splice feature will remove the last item added to the vector if it cannot locate the item referred to in the script.

So since the lightbulb had already been removed [from inserting it into the lamp], when going back to that frame, it removed the key.

The splice feature was only suppose to be active if the lightbulb had an if(hitTestObject) with the lamp.

What had happened was that instead of me scripting it so that it would remove the child, I instead made it invisible - so that it would disppear. Meaning that once the light was inserted, it was still there on top of the lamp. Thus meaning the splice was always active.

To fix this I added a removeChild after the lightbulb had (hitTestObject with the lamp.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.