Author Topic: GUIText recieving score from NGUI Checkmark?  (Read 5465 times)

Alayna

  • Guest
GUIText recieving score from NGUI Checkmark?
« on: May 11, 2012, 09:11:01 AM »
Hello, I am trying to make a simple additive menu where the user has a series of checkmarks that add different points depending on the options they choose. I have it so that the check marks are in rows of four in radio so I can only click one of each set. I also have a GUIText element in the screen that is supposed to tally up the points gained from each checkbox active. currently the script on the GUIText element is this;

Score.js

static var Score : int = 0;

function Update () {
    guiText.text = "Score:" + Score.ToString();
 }

and the script on the checkmarks are this;

CountingCode.js

function OnActivate(){
      Score.score += 10;
}

Nothing happens when I click any of the checkmarks, the score just stays at 0. I would be very happy if someone could assist me!


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: GUIText recieving score from NGUI Checkmark?
« Reply #1 on: May 11, 2012, 02:43:28 PM »
You're missing a boolean parameter in your OnActivate function. It's either "true" or "false" depending on whether the checkbox was checked.

Also why are you using a GUIText instead of an NGUI label?

Alayna

  • Guest
Re: GUIText recieving score from NGUI Checkmark?
« Reply #2 on: May 11, 2012, 07:43:46 PM »
Oh I'll fix that and see if it works when I get back to my main computer. I was using GUIText because when I was reading tutorials on score keeping they kept coming up. How would I go about using an NGUI Label for this instead?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: GUIText recieving score from NGUI Checkmark?
« Reply #3 on: May 11, 2012, 08:58:16 PM »
Use the widget tool to create a label, and there you go.

Alayna

  • Guest
Re: GUIText recieving score from NGUI Checkmark?
« Reply #4 on: May 14, 2012, 07:42:15 AM »
So I changed the CountingCode.js to include a boolean like this.

var onOff : boolean;

function Start(){
 onOff = false;
}

function OnActivate(){
  if(onOff == false){
      Score.score += 10;
      onOff = true;
}
   else {
     Score.score += 0;
     onOff = false;
     }
}

But it still isnt adding any score at all? Do you have any other suggestions to try?    


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: GUIText recieving score from NGUI Checkmark?
« Reply #5 on: May 14, 2012, 07:45:51 AM »
No, you misunderstand. Your function is missing a parameter.

function OnActivate(bool val), or however you do it in Javascript (I don't do Javascript)