[Solved] Add the value of global variable

I want to make score point that will increase after click the correct asnwer. but the score doesn’t increase, it generate 0 number. If i click the correct answer again it just generate 00 and so on. Can anyone help me?

{
  "questions": [
    {
      "question": "Apa ibukota Indonesia?",
      "options": ["Jakarta", "Bandung", "Surabaya", "Medan"],
      "answer": "Jakarta"
    },
    {
      "question": "Siapa presiden pertama Indonesia?",
      "options": ["Soekarno", "Soeharto", "Habibie", "Megawati"],
      "answer": "Soekarno"
    }
  ],
  "points_per_correct_answer": 10
}

When you add 2 strings consisting of numbers, the values of those numbers aren’t added, rather the 2 strings are concatenated.

For example, say you have the strings “123” and “456”. Adding them results in “123456”

The same is happening with your score - you are concatenating 2 strings, not adding a value. You are concatenating the current text of the textbox with the string representation of Scorepoint.

What you want to do is add points_per_correct_answer to Scorepoint, and then set the text of Score to Scorepoint. Change this:

image

To this:

> Set the variable Scorepoint add Question.points_per_correct_answer
> Set the text of Score: set to ToString(Scorepoint)

Also, don’t give a scene and global variable the same name (Scorepoint in the first event)

2 Likes

Thanks for helping me