Rock Paper Scissors Game Unityscript help

Hey all,

I’m new to Javascript, and I put together some code for a simple rock paper scissors game I’m working on. I think I have the basic flow of how it will go, but it’s not quite there. I’d love any feedback I can get on the matter. Here is the code:

#pragma strict

var btn: UnityEngine.UI.Button = rock.GetComponent.<UnityEngine.UI.Button>();
var btn: UnityEngine.UI.Button = paper.GetComponent.<UnityEngine.UI.Button>();
var btn: UnityEngine.UI.Button = paper.GetComponent.<UnityEngine.UI.Button>();

function Update() {

    if (btn: UnityEngine.UI.Button = rock.GetComponent.<UnityEngine.UI.Button>())
            human=0;
    if (btn: UnityEngine.UI.Button = paper.GetComponent.<UnityEngine.UI.Button>())
            human=1;
    if (btn: UnityEngine.UI.Button = paper.GetComponent.<UnityEngine.UI.Button>())
            human=2;

    if(human>-1){

        var computer : int=Random.value * 3;
        var results=0;


        if(human == 0 computer == 2) results=1;
        if(human == 1 computer == 0) results=1;
        if(human == 2 computer == 1) results=1;


        if(human == 0 computer == 1) results=-1;
        if(human == 1 computer == 2) results=-1;
        if(human == 2 computer == 0) results=-1;


        if(results==-1)
            GetComponent.<Text.Lose>().enabled = true;
        if(results==0)
            GetComponent.<Text.Draw>().enabled = true;
        if(results==1)
            GetComponent.<Text.Draw>().enabled = true;
    }
}

Also, here’s the UI if this helps for reference

Thanks!

This script is just… chock full of issues. I count 9 out of 40 lines that don’t have some sort of issue that’d prevent compilation (duplicate variable names, bad syntax in if statements, not using && to join your if statements, using = instead of = in if statements, and bad GetComponent syntax, are all issues that jump out at me right away), and that’s in addition to the concept of the way this is written being flawed (the buttons should call a function that you set in the button’s Inspector; you don’t check for the buttons’ status from Update).

I’ll help you work out those issues if you want, but I would honestly recommend taking a step back and working through some of the coding tutorials, and the UI tutorials would be relevant to your concept here as well.

And I recommend jumping ship and switching to C# instead of JS - having so much more learning material (especially Unity’s own tutorials) makes C# much easier to learn, and because it’s more popular, getting help on the forums is much easier.

I see what you mean. I need as much feedback as I can get, otherwise I won’t improve :stuck_out_tongue: any help is also appreciated. I’ll send a DM your way.