Variable Inconsistencies?

It looks like assigning variables are rather simple except that they do not work consistently.

Define: Fighter = $Fighter
[when][@DwarfCLASS&;#93;=Fighter[do][@DwarfFighter&;#93;[end]

Table: DwarfCLASS
30: Fighter
5: Cleric
25: Barbarian
2: Rogue

Table: DwarfFighter
Class Fighter chosen
Table: DwarfCleric
Class Cleric chosen
Table: Dwarf Barbarian
CLass Barbarian chosen
Table: DwarfRogue
Class Rogue chosen

It prints out Class Fighter Chosen randomly with any of the DwarfClass Table entries.
What am I doing wrong?

How do I assign a table result to a variable for later reference?

Comments

  • To assign a table result to a variable, you would do something like:
    Table: PickAClass
    Set: ClassName =[@RandomClass&;#93;
    

    To do it in a table row, you can also use (assuming RandomClass was a valid table)
    [@ClassName=RandomClass&;#93;
    

    To suppress output so nothing is displayed but the variable is assigned, use ==
    [@ClassName==RandomClass&;#93;
    

    Expressions nest, so you can get rid of the [when] and use the variable name as the table name
    Table: PickAClass
    Set: ClassName =[@RandomClass&;#93;
    [@{ClassName}&;#93;
    
  • //
    Define: Fighter = $Fighter
    //[when][@DwarfCLASS&;#93;=Fighter[do][@DwarfFighter&;#93;[end]
    
    Set: ClassName =[@DwarfCLASS&;#93;
    [@{ClassName}&;#93;
    
    Table: DwarfCLASS
    30: Fighter
    5: Cleric
    25: Barbarian
    2: Rogue
    
    Table: DwarfFighter
    Class Fighter chosen
    Table: DwarfCleric
    Class Cleric chosen
    Table: Dwarf Barbarian
    CLass Barbarian chosen
    Table: DwarfRogue
    Class Rogue chosen
    

    I changed the code to try what you suggested but all that reports are (missing) prompts.

    Also, I see where 2 conditions can be checked for, using when>>do>>else>>end code but what if I wanted to check for more than 2? [when]{condition}[do]{script}[else][else][else][end] ???
  • I think the problem is that your ClassNames don't match the table names below. If you change table DwarfCLASS to this:
    Table: DwarfCLASS
    30:DwarfFighter
    5:DwarfCleric
    25:Dwarf Barbarian
    2:DwarfRogue
    
    ...you should be fine.

    To your other question, as long as all the conditions are mutually exclusive, you can just link together a bunch of [when] statements, like this:

    [when]{ClassName}=DwarfFighter[do]stuff[end]&
    [when]{ClassName}=DwarfFighter[do]stuff[end]&
    [when]{ClassName}=DwarfCleric[do]otherstuff[end]&
    [when]{ClassName}=Dwarf Barbarian[do]stillotherstuff[end]
    
    (the ampersands make IPP think it's all on one line)

    Hope that helps!
  • The DwarfCLASS table is the actual class table. The other tables were just implemented for testing and I was only referencing the DwarfFighter table during said test.
    Thanks for the feedback lads. I was able to get things working as expected by using
    [@Classname=DwarfCLASS&;#93;
    
    and
    [when][{Classname}]=Fighter[do][@DwarfFighter&;#93;[end]&
    [when][{Classname}]=Cleric[do][@DwarfCleric&;#93;[end]&
    [when][{Classname}]=Rogue[do][@DwarfRogue&;#93;[end]&
    [when][{Classname}]=Barbarian[do][@DwarfBarbarian&;#93;[end]&
    

    Thanks for the tip on the ampersand.

Leave a Comment