Wiki

effect · random_list

Definition

  • Supported scope:any
  • Supported target:none

Description

Picks a random effect from the list based on the weight associated.
The weight can be a variable valid in the current scope.
Example:
random_list = {
	# enable logging the dice role in game.log
	log = yes
	seed = var_name/const/random #if specified, it will use this seed instead of scope seed for picking a random
	# some effect with an associated weight
	10 = { add_political_power=10 }
	10 = { add_political_power=100 }
	some_var = { add_political_power=1000 }
}

实战 · 配合 · 坑

实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

random_list 常用于为事件选项或决议执行后制造随机结果,例如随机赋予不同数量的政治点数、随机触发不同的国家 buff,或实现概率性的剧情分支。权重数值越大,对应分支被选中的概率越高,适合制作"骰子型"随机事件系统。

# 随机获得政治点数或设置全局旗帜,权重不同代表概率不同
random_list = {
    seed = random
    60 = {
        add_to_variable = { var = pp_reward value = 10 }
    }
    30 = {
        add_to_variable = { var = pp_reward value = 50 }
    }
    10 = {
        set_global_flag = rare_jackpot_flag
        add_to_variable = { var = pp_reward value = 200 }
    }
}

配合关系

  • hidden_effect:将 random_list 包裹其中,使随机分支的执行不在事件界面产生多余提示文本,保持界面整洁。
  • set_variable / add_to_variable:在各分支内修改变量,配合后续 check_variable 触发器对结果进行判断和利用。
  • log:可在 random_list 顶层写 log = yes,或在分支内使用 log 记录当前投中了哪条分支,便于调试。
  • if:在各分支内部用 if 加条件限制,使某些随机结果只在特定国家状态下才真正生效,避免产生逻辑错误。

常见坑

  1. 权重写成浮点数或负数random_list 的权重必须是非负整数或变量名,直接写 0.5 = { ... } 或负权重会导致脚本解析错误或行为未定义;若想用变量权重,需确保该变量在当前 scope 下已被赋值且不为负。
  2. 误以为分支会全部执行random_list 每次只选取一个分支执行,而非按概率独立触发每条分支——若需要多条效果同时以不同概率触发,应改用多个独立的 random effect 分别判断。

Hands-On Notes

Hands-on notes are AI-generated and checked against the vanilla command vocabulary — treat them as a starting point, not authoritative reference. The definition above is the game's own documentation.

Hands-On Usage

random_list is commonly used to produce randomized outcomes after event options or decisions fire — for example, granting a random amount of political power, applying different national buffs at random, or creating probabilistic story branches. The higher a branch's weight, the greater its chance of being selected, making random_list ideal for building "dice-roll" style random event systems.

# Randomly award political power or set a global flag; different weights represent different probabilities
random_list = {
    seed = random
    60 = {
        add_to_variable = { var = pp_reward value = 10 }
    }
    30 = {
        add_to_variable = { var = pp_reward value = 50 }
    }
    10 = {
        set_global_flag = rare_jackpot_flag
        add_to_variable = { var = pp_reward value = 200 }
    }
}

Synergy

  • hidden_effect: Wrap random_list inside hidden_effect to prevent the random branches from generating unwanted tooltip text in the event window, keeping the UI clean.
  • set_variable / add_to_variable: Modify variables inside individual branches, then use check_variable triggers downstream to read and act on the result.
  • log: Write log = yes at the top level of random_list, or use log inside individual branches, to record which branch was selected — useful for debugging.
  • if: Use if with conditions inside individual branches so that certain random outcomes only take effect when the country is in a specific state, preventing logic errors.

Common Pitfalls

  1. Using a float or negative number as a weight: Weights in random_list must be non-negative integers or variable names. Writing something like 0.5 = { ... } or a negative weight will cause a script parse error or undefined behavior. If you want to use a variable as a weight, make sure that variable has already been assigned a value in the current scope and is not negative.
  2. Assuming all branches execute: random_list selects and executes exactly one branch per evaluation — it does not independently roll each branch against its probability. If you need multiple effects to each trigger at their own independent probability, use multiple separate random effects instead.