SOLVED: Label math displays

Started by steptoe, Sat 03/12/2011 19:02:21

Previous topic - Next topic

steptoe

Hi all you mathematical  geniuses

Is it possible and if so how to do the following:

Int A: adds £ per correct answer and displays total on Label A.

IE £1000 per question correct = 5 correct answers= £5000 displayed on Label A.

After which:

Int B: Label B takes the total of Label A and x 3 to it and displays it (£15000) on Label B.

Meanwhile:

Int C: Label C takes the total of Label A and / 5 from it and displays it on Label C.

IE Label A £5000 Label B £15000 Label C 1000

Grateful if anyone can help

cheers




It's not over until the fat lady sings..

Khris

Code: ags
function UpdateLabels(int money) {
  a += money;
  LabelA.Text = String.Format("£%d", a);
  LabelB.Text = String.Format("£%d", a*3);
  LabelC.Text = String.Format("£%d", a/5);
}

  ...
  if (question was answered correctly) UpdateLabel(1000);
  ...


Good thing I studied mathematics for a few years :=

steptoe

#2
Good job someone did  :=

I'll give it a whirl

cheers Khris

EDIT: Created 3 LABELS: LabelA   LabelB  LabelC
Made 3 Ints A B C..

I put Int A at 5000 start.

Put you code in room yet only A (5000) shows whilst others display 0

Code: ags

function UpdateLabels(int money) {
  A += money;
  LabelA.Text = String.Format("£%d", A);
  LabelB.Text = String.Format("£%d", A*3);
  LabelC.Text = String.Format("£%d", A/5);


and

Code: ags

function room_AfterFadeIn()
{
  
LabelA.Text = String.Format("£: %d", A);

LabelB.Text = String.Format("£: %d", B);

LabelC.Text = String.Format("£: %d", C);

}


:(





It's not over until the fat lady sings..

Khris

You have to call the function for it to actually do something.
Remove the three lines you put in AfterFadein, you can also delete B and C, you don't need them.

Then put this line in AfterFadein:

Code: ags
  UpdateLabels(0);

steptoe

#4
Hi

wont take updateLabels(0) in after fadein (UNDEFINED error)

I can definately see the advantage of updating all labels in one script.

It makes it more lengthy if i update all labels frequently like:

Example after awarding £ To Int A:

Code: ags

LabelA.Text = String.Format("£: %d", A);

LabelB.Text = String.Format("£: %d", A*3);

LabelC.Text = String.Format("£: %d", A/5);


Have deleted ints B and C and just have A.

Works but is repetitive. Could add (Labels) to globally Rep Exe Always.

cheers


It's not over until the fat lady sings..

monkey0506

You need to post the exact code you are using and the exact error message you are getting. Coz the code Khris posted is fine.

steptoe

#6
Hi Monkey/Khris

I have INT 'A' set at 1000 for test run as well as 3 Labels A, B and C.

I then used this as per Khris which works:

Code: ags

function UpdateLabels(int money) {
  A += money;
  LabelA.Text = String.Format("£%d", A);
  LabelB.Text = String.Format("£%d", A*3);
  LabelC.Text = String.Format("£%d", A/5);
}


and this which gives an error:

Code: ags

function room_AfterFadeIn()
{
  UpdateLabels(0); // Undefined token 'UpdateLabels' 

}


Using AGS 3.2.1.111



It's not over until the fat lady sings..

monkey0506

Functions need to be imported if they're going to be used in other scripts. So if you put the UpdateLabels function in GlobalScript.asc, then you would need to put the following in the GlobalScript.ash header file:

Code: ags
import function UpdateLabels(int money);


Then it will compile.

Oh, and just to make sure you don't get them confused, never put a function into a header, only put imports, and struct and enum definitions in the ASH header files (nothing else belongs there!).

steptoe

#8
Hi Monkey

took out the Room update Label part and added import update Labels as instructed.

Global ash at top:

Code: ags

import function UpdateLabels(int money); 


and this in Global asc:

Code: ags

function repeatedly_execute_always() {
  
//LABELS £

  LabelA.Text = String.Format("£: %d", A);
  LabelB.Text = String.Format("£: %d", A*3);
  LabelC.Text = String.Format("£: %d", A/5);

}


In room script:
Code: ags

A=(A+9000);


Works a treat as I only need to adjust Int A.

Solved.

Cheers Guys

:=

It's not over until the fat lady sings..

SMF spam blocked by CleanTalk