Hello all,
I was wondering if there was any way to make a trigger that can randomly choose a different trigger out of three or four triggers and run the randomly chosen trigger. It'd be amazing if anyone has any info or tips.
Thanks!
A switch "Macro" isn't a macro at all. It is actually a cornerstone of modern programming. Essentially you pass a variable into the switch statement and depending on what the value of that variable is a segment of code will be run. See below:
Variable i = RandomInt(1, 100)
Switch (i)
{
case:1
Say "Hello";
break;
case:2
Say "World";
break;
default:
Say "Default";
break;
}
In this example, i is a random variable between 1 and 100. If (i = 1) then "Hello" is printed. If (i=2) then "World" is printed. If (i = something else) then the default action is run of "Default" being printed.
Here is an Example of a Switch Statement using Java:
class SwitchDemo {
public static void main(String[] args) {
int month = 8;
switch (month) {
case 1: System.out.println("January"); break;
case 2: System.out.println("February"); break;
case 3: System.out.println("March"); break;
case 4: System.out.println("April"); break;
case 5: System.out.println("May"); break;
case 6: System.out.println("June"); break;
case 7: System.out.println("July"); break;
case 8: System.out.println("August"); break;
case 9: System.out.println("September"); break;
case 10: System.out.println("October"); break;
case 11: System.out.println("November"); break;
case 12: System.out.println("December"); break;
default: System.out.println("Invalid month.");break;
}
}
}
Here is an example of a switch statement using c#
{
public enum State { One, Two, Three, Four };
public void DoASwitch(State mystate)
{
switch (mystate)
{
case State.One:
Console.WriteLine("I'm in state one!");
break;
case State.Two:
Console.WriteLine("I'm in state two!");
goto case State.Four;
case State.Three:
Console.WriteLine("I'm in state three!");
goto case State.Two;
case State.Four:
Console.WriteLine("I'm in state four!");
goto case State.One;
}
}
If you want to excel with your mapping you should take some time to read up on all the actions in the general section (Not "-General").
If Then Else
Switch
While
For each
ect...
EDIT:
I don't know why this forum refuses to accept formatting :(
There is a much better way to do this guys. You don't need to use Switch or If/Else at all!
See below:
Run Random Trigger
Events
Local Variables
randomTriggers = No Trigger
Conditions
Actions
Variable - Set randomTriggers[0] = Trigger 1
Variable - Set randomTriggers[1] = Trigger 1
Trigger - Run randomTriggers[(Random integer between 0 and 1)] (Check Conditions, Don't Wait until it
finishes)
Notes:
randomTriggers is a variable of type Trigger, set to Array of size 2 in the above example (set this to the number of random triggers)
You would probably create randomTriggers variable as a global, and have a separate trigger to initialize it to set the values instead of setting them each time it's run.
Everything in the trigger editor that generates code are actually macro's, there is no switch statement in galaxy, just if/else if. So it is in fact a code generation macro.
And stick it in code tags, see markup documentation for more info.
Hello all, I was wondering if there was any way to make a trigger that can randomly choose a different trigger out of three or four triggers and run the randomly chosen trigger. It'd be amazing if anyone has any info or tips. Thanks!
use If Then Else
Create a local variable name random of type integer
Do this :
Variable - Set random = (Random integer between 1 and 3) You can change the 3 for the number of trigg
If random = 1 Then run trigger 1 Else no action
If random = 2 Then run trigger 2 Else no action
If random = 3 Then run trigger 3 Else no action
Do a switch on a random integer, or store the triggers in an array and use a random number as the index and run that.
@TheNiceGuy: Go
Using if else has no purpose here, the multiple if else if macro would be better, switch macro would be even better.
Never mind... do as above
I've never used a switch macro before... could you explain the steps a little bit?
@Aneth0r: Go
A switch "Macro" isn't a macro at all. It is actually a cornerstone of modern programming. Essentially you pass a variable into the switch statement and depending on what the value of that variable is a segment of code will be run. See below:
Variable i = RandomInt(1, 100)
Switch (i) {
case:1
Say "Hello";
break;
case:2
Say "World";
break;
default:
Say "Default";
break;
}
In this example, i is a random variable between 1 and 100. If (i = 1) then "Hello" is printed. If (i=2) then "World" is printed. If (i = something else) then the default action is run of "Default" being printed.
Here is an Example of a Switch Statement using Java:
class SwitchDemo { public static void main(String[] args) {
int month = 8; switch (month) { case 1: System.out.println("January"); break; case 2: System.out.println("February"); break; case 3: System.out.println("March"); break; case 4: System.out.println("April"); break; case 5: System.out.println("May"); break; case 6: System.out.println("June"); break; case 7: System.out.println("July"); break; case 8: System.out.println("August"); break; case 9: System.out.println("September"); break; case 10: System.out.println("October"); break; case 11: System.out.println("November"); break; case 12: System.out.println("December"); break; default: System.out.println("Invalid month.");break; } } }
Here is an example of a switch statement using c#
{ public enum State { One, Two, Three, Four };
public void DoASwitch(State mystate) { switch (mystate) { case State.One: Console.WriteLine("I'm in state one!"); break; case State.Two: Console.WriteLine("I'm in state two!"); goto case State.Four; case State.Three: Console.WriteLine("I'm in state three!"); goto case State.Two; case State.Four: Console.WriteLine("I'm in state four!"); goto case State.One; } }
If you want to excel with your mapping you should take some time to read up on all the actions in the general section (Not "-General").
If Then Else Switch While For each ect...
EDIT: I don't know why this forum refuses to accept formatting :(
Thanks everyone. Even though I was a tad bit confused, it seems as though I've got it working.
Thanks again. :D
There is a much better way to do this guys. You don't need to use Switch or If/Else at all!
See below:
Run Random Trigger
Notes:
Thanks.
That one works equally as well, with less line clutter. :D
@KineMorto: Go
Everything in the trigger editor that generates code are actually macro's, there is no switch statement in galaxy, just if/else if. So it is in fact a code generation macro.
And stick it in code tags, see markup documentation for more info.
@KratsAU: Go
I already stated that above.
I would do this like so
Var Int = Random Number 1-3
Switch{
-if Int = 1 then run trigger 1
-if Int = 2 then run trigger 2
-if Int = 3 then run trigger 3
}