Trying to display the total of 2 scores but there is an error

How do I…

I have 2 different scores due to the player picking 2 different items. I have added an ending scene where the “total” text should display the addition of these 2 scores.
The code that i have inputed:
Change the text of total: set to ToString(ToNumber(GlobalVariable(SCORE_ORANGE))) + ToString(ToNumber(GlobalVariable(SCORE_YELLOW)))

Instead this is the error it gives me:
“You tried to use an expression that returns a number, but a string is expected. Use “ToString” if you need to convert a number to a string”

Any suggessions? I don’t know what to do.

Hi,
you don’t need all these long expressions any more, since the variable system has been changed a while ago. After declaring the variables in the variable menu, you can just call them in the events by their name.
Score

You can just write the variable names without any other expression but then their values are interpreted as strings and displayed together. With the ToString-expression the values of both variables will be interpreted as numbers first, added and the total value displayed.

Thanks, I tried it, stopped showing the error but it still returns the score as a string and not a total.

You have additional rounded brackets just before and after the “+” sign. As a result, you are creating a string out of score_orange, and appending score_yellow to it:

image


@Drona’s action add the two scores before converting the result to a string:

image

2 Likes

Thank you so much, don’t know how i didn’t catch that the first time, and yes it works!