Staredit Network > Forums > SC1 UMS Mapmaking Assistance > Topic: Switch randomization triggers not running in order
Switch randomization triggers not running in order
Jan 4 2025, 2:39 pm
By: sethmachine  

Jan 4 2025, 2:39 pm sethmachine Post #1



Hi,

I am doing the technique to get a random value (power of 2) by randomizing a switch N times and summing each power of 2 until I have a random value I need.

What I noticed is that my checks for switch being set are not running in their trigger order, and I get output that's out of order. This seems to cause other problems.

What is wrong with my trigger set up? Do I need to explicitly clear the switch each time a power of 2 is added? That seemed to fix the out of order triggers. Triggers below, and a test map is attached showing the problem. Note that I am also using hyper triggers.


Quote
{'_conditions': [DeathsCondition(_group=<PlayerId.PLAYER_6: (5, 'Player 6')>, _comparator=<NumericComparator.EXACTLY: (10, 'Exactly')>, _amount=0, _unit=<UnitId.ALAN_SCHEZAR_TURRET: (18, 'Alan Schezar Turret')>, _flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [SetDeathsAction(_group=<PlayerId.CURRENT_PLAYER: (13, 'Current Player')>, _unit=<UnitId.ALAN_SCHEZAR_TURRET: (18, 'Alan Schezar Turret')>, _amount=1, _amount_modifier=<AmountModifier.SET_TO: (7, 'Set to')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), WaitAction(_milliseconds=0, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), SetDeathsAction(_group=<PlayerId.CURRENT_PLAYER: (13, 'Current Player')>, _unit=<UnitId.ALAN_SCHEZAR_TURRET: (18, 'Alan Schezar Turret')>, _amount=0, _amount_modifier=<AmountModifier.SET_TO: (7, 'Set to')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), WaitAction(_milliseconds=0, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), PreserveTrigger(_flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [AlwaysCondition(_flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [SetSwitchAction(_switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _switch_action=<SwitchAction.RANDOMIZE: (11, 'Randomize switch')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [SwitchCondition(_switch_state=<SwitchState.SET: (2, 'Switch is set')>, _switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [DisplayTextMessageAction(_text=RichString(_value='1'), _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), SetDeathsAction(_group=<PlayerId.PLAYER_6: (5, 'Player 6')>, _unit=<UnitId.CANTINA: (181, 'Cantina')>, _amount=1, _amount_modifier=<AmountModifier.ADD: (8, 'Add')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [AlwaysCondition(_flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [SetSwitchAction(_switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _switch_action=<SwitchAction.RANDOMIZE: (11, 'Randomize switch')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [SwitchCondition(_switch_state=<SwitchState.SET: (2, 'Switch is set')>, _switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [DisplayTextMessageAction(_text=RichString(_value='2'), _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), SetDeathsAction(_group=<PlayerId.PLAYER_6: (5, 'Player 6')>, _unit=<UnitId.CANTINA: (181, 'Cantina')>, _amount=2, _amount_modifier=<AmountModifier.ADD: (8, 'Add')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [AlwaysCondition(_flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [SetSwitchAction(_switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _switch_action=<SwitchAction.RANDOMIZE: (11, 'Randomize switch')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [SwitchCondition(_switch_state=<SwitchState.SET: (2, 'Switch is set')>, _switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [DisplayTextMessageAction(_text=RichString(_value='4'), _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), SetDeathsAction(_group=<PlayerId.PLAYER_6: (5, 'Player 6')>, _unit=<UnitId.CANTINA: (181, 'Cantina')>, _amount=4, _amount_modifier=<AmountModifier.ADD: (8, 'Add')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [AlwaysCondition(_flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [SetSwitchAction(_switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _switch_action=<SwitchAction.RANDOMIZE: (11, 'Randomize switch')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [SwitchCondition(_switch_state=<SwitchState.SET: (2, 'Switch is set')>, _switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [DisplayTextMessageAction(_text=RichString(_value='8'), _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), SetDeathsAction(_group=<PlayerId.PLAYER_6: (5, 'Player 6')>, _unit=<UnitId.CANTINA: (181, 'Cantina')>, _amount=8, _amount_modifier=<AmountModifier.ADD: (8, 'Add')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [AlwaysCondition(_flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [SetSwitchAction(_switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _switch_action=<SwitchAction.RANDOMIZE: (11, 'Randomize switch')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [SwitchCondition(_switch_state=<SwitchState.SET: (2, 'Switch is set')>, _switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [DisplayTextMessageAction(_text=RichString(_value='16'), _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), SetDeathsAction(_group=<PlayerId.PLAYER_6: (5, 'Player 6')>, _unit=<UnitId.CANTINA: (181, 'Cantina')>, _amount=16, _amount_modifier=<AmountModifier.ADD: (8, 'Add')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [AlwaysCondition(_flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [SetSwitchAction(_switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _switch_action=<SwitchAction.RANDOMIZE: (11, 'Randomize switch')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [SwitchCondition(_switch_state=<SwitchState.SET: (2, 'Switch is set')>, _switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [DisplayTextMessageAction(_text=RichString(_value='32'), _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), SetDeathsAction(_group=<PlayerId.PLAYER_6: (5, 'Player 6')>, _unit=<UnitId.CANTINA: (181, 'Cantina')>, _amount=32, _amount_modifier=<AmountModifier.ADD: (8, 'Add')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [AlwaysCondition(_flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [SetSwitchAction(_switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _switch_action=<SwitchAction.RANDOMIZE: (11, 'Randomize switch')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}
{'_conditions': [SwitchCondition(_switch_state=<SwitchState.SET: (2, 'Switch is set')>, _switch=RichSwitch(_custom_name=RichString(_value='kingdoms-assignment-switch'), _index=None), _flags=TriggerConditionFlags(unknown=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_actions': [DisplayTextMessageAction(_text=RichString(_value='64'), _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False)), SetDeathsAction(_group=<PlayerId.PLAYER_6: (5, 'Player 6')>, _unit=<UnitId.CANTINA: (181, 'Cantina')>, _amount=64, _amount_modifier=<AmountModifier.ADD: (8, 'Add')>, _flags=TriggerActionFlags(ignore_wait_or_transmission_once=False, disabled=False, always_display=False, unit_properties_is_used=False, unit_type_is_used=False))], '_players': {<PlayerId.PLAYER_1: (0, 'Player 1')>}}


Attachments:
plain-dirt-2025-01-03.scx
Hits: 1 Size: 668.12kb
triggers.jsonl
Hits: 0 Size: 12.03kb



None.

Jan 4 2025, 4:25 pm Ultraviolet Post #2

We do a little trolling

That's not very readable. Here's a working single switch example of randomizing a DC between 0 and 31 every trigger cycle. Personally, I prefer using multiple switches to accomplish this as it's a little cleaner implementation, but this should work about the same.

Trigger("Player 1"){
Conditions:
Always();

Actions:
Preserve Trigger();
Set Deaths("Current Player", "Independent Command Center", Set To, 0);
Set Switch("Switch1", randomize);
}

//-----------------------------------------------------------------//

Trigger("Player 1"){
Conditions:
Switch("Switch1", Set);

Actions:
Preserve Trigger();
Set Deaths("Current Player", "Independent Command Center", Add, 1);
}

//-----------------------------------------------------------------//

Trigger("Player 1"){
Conditions:
Always();

Actions:
Preserve Trigger();
Set Switch("Switch1", randomize);
}

//-----------------------------------------------------------------//

Trigger("Player 1"){
Conditions:
Switch("Switch1", Set);

Actions:
Preserve Trigger();
Set Deaths("Current Player", "Independent Command Center", Add, 2);
}

//-----------------------------------------------------------------//

Trigger("Player 1"){
Conditions:
Always();

Actions:
Preserve Trigger();
Set Switch("Switch1", randomize);
}

//-----------------------------------------------------------------//

Trigger("Player 1"){
Conditions:
Switch("Switch1", Set);

Actions:
Preserve Trigger();
Set Deaths("Current Player", "Independent Command Center", Add, 4);
}

//-----------------------------------------------------------------//

Trigger("Player 1"){
Conditions:
Always();

Actions:
Preserve Trigger();
Set Switch("Switch1", randomize);
}

//-----------------------------------------------------------------//

Trigger("Player 1"){
Conditions:
Switch("Switch1", Set);

Actions:
Preserve Trigger();
Set Deaths("Current Player", "Independent Command Center", Add, 8);
}

//-----------------------------------------------------------------//

Trigger("Player 1"){
Conditions:
Always();

Actions:
Preserve Trigger();
Set Switch("Switch1", randomize);
}

//-----------------------------------------------------------------//

Trigger("Player 1"){
Conditions:
Switch("Switch1", Set);

Actions:
Preserve Trigger();
Set Deaths("Current Player", "Independent Command Center", Add, 16);
}

//-----------------------------------------------------------------//



My Projects:

Impossible Ultraviolet | Impossible UV 2 | Impossible UV 3
Mercenaries 2020 | Mercenaries III
Squad Defense

Legacy Projects (No guarantee of functionality in modern SC):

Pixel Adventure 2 | Space Snipers | Control the Ball

______________________________________________

Join me in Torn City

Jan 5 2025, 8:39 am NudeRaider Post #3

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

You check trigger order in Scmdraft, not some json file. Not familiar with this type of trigger generation, so I can't give any tips with it.

But in the end the execution order actually doesn't matter. Yes, you gonna get a different random number than you would've with "correct" ordering, but it's just as random so it should be good anyhow, right?




Jan 5 2025, 5:09 pm Ultraviolet Post #4

We do a little trolling

Quote
But in the end the execution order actually doesn't matter.

Depending on how the triggers are built (I can't read that json trigger stuff either), it could matter greatly. For example, I usually establish a reset at the top of the trigger list so that the number is starting from 0 every cycle. If that reset got put out of order, it could affect it in such a way that you never got a random number at all, you could just get stuck with it generating 0 every time if it was at the bottom of the list instead.



My Projects:

Impossible Ultraviolet | Impossible UV 2 | Impossible UV 3
Mercenaries 2020 | Mercenaries III
Squad Defense

Legacy Projects (No guarantee of functionality in modern SC):

Pixel Adventure 2 | Space Snipers | Control the Ball

______________________________________________

Join me in Torn City

Jan 5 2025, 6:18 pm NudeRaider Post #5

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

Quote from Ultraviolet
Depending on how the triggers are built (I can't read that json trigger stuff either), it could matter greatly. For example, I usually establish a reset at the top of the trigger list so that the number is starting from 0 every cycle. If that reset got put out of order, it could affect it in such a way that you never got a random number at all, you could just get stuck with it generating 0 every time if it was at the bottom of the list instead.
Yeah the reset trigger has to be above all others. For all the others, namely randomizing and addition it doesn't matter. Randomization can even happen one or more trigger cycles ahead of time.

At least for the common methods I can think of.




Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[12:07 am]
Vrael -- NudeRaider
NudeRaider shouted: Vrael ranting still is though
you're a gentleman and a scholar, thank you
[10:07 pm]
NudeRaider -- ya why phone people when you can just write letters
[09:37 pm]
IskatuMesk -- I have never and will never own a phone
[09:15 pm]
NudeRaider -- Vrael ranting still is though
[09:14 pm]
ClansAreForGays -- anticapitalism isnt edgy anymore
[03:31 pm]
Vrael -- it only costs 50% of my post-tax salary for life and in return I get to also become a drone whose sole purpose is CAPITALISM
[03:30 pm]
Vrael -- pssht, you're still using a phone? I just record 100% of my life using my ElonBrainChip
[2026-4-13. : 2:13 pm]
NudeRaider -- bro I don't go anywhere without my phone to record anything significant
[2026-4-13. : 1:28 pm]
Vrael -- Zoan
Zoan shouted: not if u wer there
id say even if you were there its tricky, human memory can be very faulty
[2026-4-12. : 11:55 pm]
Zoan -- not if u wer there
Please log in to shout.


Members Online: Zycorax