• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Random equations, Variables not working

Status
Not open for further replies.
Level 6
Joined
Apr 15, 2012
Messages
205
I have made a map where you have to answer random equations. If you type in the right answer, you will be rewarded.

I have 3 global integer variables, their values are 0 from the beginning. The first two hold the factors/terms that are multiplicated/added/subtracted in the equation. The third one holds the value of the equation.
My variables and triggers:

  • Operations = 0 <Integer>
  • Number 1 = 0 <Integer>
  • Number 2 = 0 <Integer>
  • Answer = 0 <Integer>
  • Generator
  • Answer
My first trigger (Generator):

  • Generator
    • Events
      • Game - Map initialization
    • Local Variables
    • Conditions
    • Actions
      • Variable - Set Operations = (Random integer between 1 and 3)
      • Variable - Set Number 1 = (Random integer between 5 and 10)
      • Variable - Set Number 2 = (Random integer between 1 and 5)
      • General - If (Conditions) then do (Actions) else do (Actions)
        • If
          • Operations == 1
        • Then
          • UI - Display ((Text(Number 1)) + (" + " + (Text(Number 2)))) for (All players) to Subtitle area
          • Variable - Set Answer = (Number 1 + Number 2)
          • Trigger - Turn Answer On
        • Else
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • Operations == 2
            • Then
              • UI - Display ((Text(Number 1)) + (" - " + (Text(Number 2)))) for (All players) to Subtitle area
              • Variable - Set Answer = (Number 1 - Number 2)
              • Trigger - Turn Answer On
            • Else
              • UI - Display ((Text(Number 1)) + (" · " + (Text(Number 2)))) for (All players) to Subtitle area
              • Variable - Set Answer = (Number 1 * Number 2)
              • Trigger - Turn Answer On
It choses an operation and the values of the variables are set. Then it turns on the second trigger (Answer):

  • Answer
    • Events
      • Game - Player Any Player types a chat message containing (String(Answer)), matching Exactly
    • Local Variables
    • Conditions
    • Actions
      • Player - Modify player (Triggering player) Minerals: Add 250
      • Player - Modify player (Triggering player) Vespene: Add 125
The problem is that when I type in the right number, it doesn't respond. When I type in 0, (the starting value of the Answer variable) it responds.

I have tried to change the starting values of the variables and then value of the required number to be typed in would change.

Since several questions will be asked I can't do this:

  • Digit 1 = (Random integer between 1 and 5) <Integer>
  • Digit 2 = (Random integer between 5 and 10) <Integer>
  • Answer Addition = (Digit 1 + Digit 2) <Integer>
  • Digit 3 = (Random integer between 5 and 10) <Integer>
  • Digit 4 = (Random integer between 1 and 5) <Integer>
  • Answer Subtraction = (Digit 3 - Digit 4) <Integer>
  • Digit 5 = (Random integer between 1 and 5) <Integer>
  • Digit 6 = (Random integer between 5 and 10) <Integer>
  • Answer Multiplication = (Digit 5 * Digit 6) <Integer>
Please help me with this. I want it to work so the values of the variables are affected by the first trigger.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
There are 2 ways you could go about this.
1. Parse all chat messages from the player checking if any are the right answer.
2. Every time the answer is changed you destroy the trigger, re-create the trigger and attach the chat event to it again but with the new answer.

Solution 2 will require at least some Galaxy script directly as dynamic events do not seem natively supported by GUI.
 
Level 6
Joined
Apr 15, 2012
Messages
205
I forgot to mention that the second trigger does everything right. It writes out the
"Number 1 + Number 2" thing. The problem should be in the second trigger I think. But I can't find any error there either.
 
Level 6
Joined
Apr 15, 2012
Messages
205
So if I get it right, in the second trigger, the event picks the Answer variable with the starting value. So I have to update it by destroying it and then recreating it.
 
Status
Not open for further replies.
Top