• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Noob To Variables - Need Help

Status
Not open for further replies.
Level 1
Joined
May 1, 2020
Messages
5
Trying to work on a trigger involving variables which is my weakness, along with custom scripts. Trying to make an item have a random chance of spawning in a choice of 4 different regions. Example: 30 seconds passes, the item spawns in one of those four regions, not knowing which region it will spawn it. Not sure if there's a way to do it without variables, but I looked up some answers that involve variables. Here is the noob question.

I Need as following action: Set (Variable Name) = (Center Of Region[Random integer number between 1-4)])

I can get to: Set (Variable Name) = (Center Of Region...

What is the trigger name and method to finding the trigger name to add the "Random integer number between 1-4" part? I'm having a really hard time finding it as I am not used to Variable GUI.

Thanks.
 
Level 20
Joined
Feb 23, 2014
Messages
1,264
You mean something like this?

  • Set <point variable> = (Center of <region variable>[(Random integer number between X and Y)])
If so, first thing you need is a Region Array Variable (with your desired regions assigned to different indexes of that variable). Then you go:
- Set Variable action
- Choose your point variable as the variable that's being set
- As for the Value field: click it, choose Center of Region, click on the (Playable Map Area), use your region variable here
- As for the Index field: the function you're looking for is "Math - Random Number"

---

Though, as a personal recommendation - I'd suggest using a Point Array Variable instead.

Like this:

1) Set your points at map initialization (or better yet, during the first execution of the spawning trigger):

  • Set <Point Variable>[0] = (Center of <Region 1>)
  • Set <Point Variable>[1] = (Center of <Region 2>)
  • Set <Point Variable>[2] = (Center of <Region 3>)
  • Set <Point Variable>[3] = (Center of <Region 4>)
2) And then when you want to create an item:

  • Item - Create <Item Type> at <Point Variable>[(Random integer number between 0 and 3)]
3) Once you permanently turn off your item spawning trigger, you can destroy the points:

  • Custom script: call RemoveLocation(udg_<Point Variable>[0])
  • Custom script: call RemoveLocation(udg_<Point Variable>[1])
  • Custom script: call RemoveLocation(udg_<Point Variable>[2])
  • Custom script: call RemoveLocation(udg_<Point Variable>[3])
Since you're struggling with scripts, here's a clarification - let's say you call your Point Variable "SpawnPoint", then the custom scripts above should look like this:

  • Custom script: call RemoveLocation(udg_SpawnPoint[0])
P.S. You might ask - does this leak? No, it doesn't. A leak happens when you create an "object" that is stored inside the memory despite no longer being useful. Here your set of points is being reused, so for as long as your item spawning trigger is running, that's not a leak.

--- BONUS ---

If you'd like, you could have it all in a single trigger - for example, like this:

  • Events
    • Time - Every 30.00 seconds of game time
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Execution count of (This trigger)) Equal to 1
      • Then - Actions
        • Set ExecutionCount = (Random integer number between 1 and 10)
        • Set SpawnPoint[0] = (Center of SpawnArea1 <gen>)
        • Set SpawnPoint[1] = (Center of SpawnArea2 <gen>)
        • Set SpawnPoint[2] = (Center of SpawnArea3 <gen>)
        • Set SpawnPoint[3] = (Center of SpawnArea4 <gen>)
      • Else - Actions
        • -------- Do Nothing --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Execution count of (This trigger)) Less than or equal to ExecutionCount
      • Then - Actions
        • Item - Create Orb of Frost at SpawnPoint[(Random integer number between 0 and 3)]
      • Else - Actions
        • Trigger - Turn off (This trigger)
        • Custom script: call RemoveLocation(udg_SpawnPoint[0])
        • Custom script: call RemoveLocation(udg_SpawnPoint[1])
        • Custom script: call RemoveLocation(udg_SpawnPoint[2])
        • Custom script: call RemoveLocation(udg_SpawnPoint[3])
 
Last edited:

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,724
@MasterBlaster
That's a neat idea with the execution count, but I think it might confuse him, especially if he wants the trigger to run indefinitely.

@Pikachu
Using MasterBlasters trigger, you should set ExecutionCount to be equal to the total number of times you want the trigger to run. So if you set ExecutionCount to 10, the trigger will run 10 times in total before turning off.
However, if you don't want this limit to how many times it can run, I'd recommend deleting the ExecutionCount variable and removing the second If Then Else statement at the bottom. Instead, simply run the action "Item - Create YOUR ITEM at SpawnPoint[(Random integer number between 0 and 3)]" in it's place.
 
Last edited:
Level 1
Joined
May 1, 2020
Messages
5
You mean something like this?

  • Set <point variable> = (Center of <region variable>[(Random integer number between X and Y)])
If so, first thing you need is a Region Array Variable (with your desired regions assigned to different indexes of that variable). Then you go:
- Set Variable action
- Choose your point variable as the variable that's being set
- As for the Value field: click it, choose Center of Region, click on the (Playable Map Area), use your region variable here
- As for the Index field: the function you're looking for is "Math - Random Number"

---

Though, as a personal recommendation - I'd suggest using a Point Array Variable instead.

Like this:

1) Set your points at map initialization (or better yet, during the first execution of the spawning trigger):

  • Set <Point Variable>[0] = (Center of <Region 1>)
  • Set <Point Variable>[1] = (Center of <Region 2>)
  • Set <Point Variable>[2] = (Center of <Region 3>)
  • Set <Point Variable>[3] = (Center of <Region 4>)
2) And then when you want to create an item:

  • Item - Create <Item Type> at <Point Variable>[(Random integer number between 0 and 3)]
3) Once you permanently turn off your item spawning trigger, you can destroy the points:

  • Custom script: call RemoveLocation(udg_<Point Variable>[0])
  • Custom script: call RemoveLocation(udg_<Point Variable>[1])
  • Custom script: call RemoveLocation(udg_<Point Variable>[2])
  • Custom script: call RemoveLocation(udg_<Point Variable>[3])
Since you're struggling with scripts, here's a clarification - let's say you call your Point Variable "SpawnPoint", then the custom scripts above should look like this:

  • Custom script: call RemoveLocation(udg_SpawnPoint[0])
P.S. You might ask - does this leak? No, it doesn't. A leak happens when you create an "object" that is stored inside the memory despite no longer being useful. Here your set of points is being reused, so for as long as your item spawning trigger is running, that's not a leak.

--- BONUS ---

If you'd like, you could have it all in a single trigger - for example, like this:

  • Events
    • Time - Every 30.00 seconds of game time
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Execution count of (This trigger)) Equal to 1
      • Then - Actions
        • Set ExecutionCount = (Random integer number between 1 and 10)
        • Set SpawnPoint[0] = (Center of SpawnArea1 <gen>)
        • Set SpawnPoint[1] = (Center of SpawnArea2 <gen>)
        • Set SpawnPoint[2] = (Center of SpawnArea3 <gen>)
        • Set SpawnPoint[3] = (Center of SpawnArea4 <gen>)
      • Else - Actions
        • -------- Do Nothing --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Execution count of (This trigger)) Less than or equal to ExecutionCount
      • Then - Actions
        • Item - Create Orb of Frost at SpawnPoint[(Random integer number between 0 and 3)]
      • Else - Actions
        • Trigger - Turn off (This trigger)
        • Custom script: call RemoveLocation(udg_SpawnPoint[0])
        • Custom script: call RemoveLocation(udg_SpawnPoint[1])
        • Custom script: call RemoveLocation(udg_SpawnPoint[2])
        • Custom script: call RemoveLocation(udg_SpawnPoint[3])

It looks like I may have solved my first self-made variable trigger thanks to you. Will let you know how it works out. Thank you :)
 
Level 1
Joined
May 1, 2020
Messages
5
@MasterBlaster
That's a neat idea with the execution count, but I think it might confuse him, especially if he wants the trigger to run indefinitely.

@Pikachu
Using MasterBlasters trigger, you should set ExecutionCount equal to the total number of times you want the trigger to run. So if you set ExecutionCount to 10, the trigger will run 10 times in total before turning off.
However, if you don't want this limit to how many times it runs, I'd recommend deleting the ExecutionCount variable and removing the second If Then Else statement at the bottom. Instead, simply run the action "Item - Create Orb of Frost at SpawnPoint[(Random integer number between 0 and 3)]" in it's place.

Ok, thank you for the heads up!
 
Level 20
Joined
Feb 23, 2014
Messages
1,264
@MasterBlaster
That's a neat idea with the execution count, but I think it might confuse him, especially if he wants the trigger to run indefinitely.
Well, I wanted it to be more of a fun example of something that he could do if he wanted to, but you're probably right - I went a bit overboard and didn't communicate my intentions too clearly.

So yeah, @Pikachu - just like Uncle said, my trigger was just a fun idea. Follow Uncle's instructions to adjust it to your needs and if you need any further assistance, don't hesitate to ask :)
 
Level 1
Joined
May 1, 2020
Messages
5
Well, I wanted it to be more of a fun example of something that he could do if he wanted to, but you're probably right - I went a bit overboard and didn't communicate my intentions too clearly.

So yeah, @Pikachu - just like Uncle said, my trigger was just a fun idea. Follow Uncle's instructions to adjust it to your needs and if you need any further assistance, don't hesitate to ask :)

Okay no worries :)
Will upload the triggers for it so you guys can check them out after I make sure it works properly.
 
Status
Not open for further replies.
Top