Trouble with variables

After a long time I came back to this because I wanted to write a random mission generator for a game about sailing ships in the Baltic Sea. But I am having trouble getting variables to work the way I want. I read through the documentation in the program and tried to find examples in this forum, copied from my own earlier code that had variables even, but nothing I tried worked. Please help.

The base line is like this:

Table: Available Missions
45: Escort for Trading Convoy: \nNation: [@RandomBalticNation]\nTarget Port: [@RandomBalticPort]\nCargo: [@RandomCargo]\nVessels in Party: [!{1d6} RandomTradingConvoy >> implode]\nPay offered for success: [@RandomConvoyPay]
25: Pirate Hunting
10: Sea Monster Hunting
15: Mercenary in Naval Battle

Currently working on the trading escort, so the rest is not yet finished.

I wanted to have it so the Pay being offered is based on the Cargo being carried and perhaps also on the amount and kind of ships that the convoy consists of: Higher value cargo = more risk for pirate or monster attack -> more pay.

I did my random cargo table like this, just with a few examples:

Table: RandomCargo
50:Hard Husk Grains
40:Hemp and Flax
30:Ship grade Timber
20:Iron bars

Then the table that gives the pay based on the cargo:

Table: RandomConvoyPay
[when] {$RC} = Iron bars [do] [@ConvoyHighPay] [end]
[when] {$RC} = Hemp and Flax [do] [@ConvoyMediumPay][end]

Variable set as:
Set: RC = [@RandomCargo]

But the output always comes back empty. I tried changing various bits and the location that I put the variable definition, but it won't matter (in one place where I put that it even crashed the program)

What is going wrong? How can it be fixed? Thank you for any help.


  • I would assign the pay or a pay multiplier right in the RandomCargo table.

    Table: RandomCargo
    50: {paymult==2) Grains
    40: {paymult==3) Timber

    Use the double = so that it assigns the value but doesnt output the number. Then you can use that number when calculating the pay for that shipment.

  • I'm getting a value in RC. There's an issue with Table RandomConvoyPay though. You probably want it to consider every When possibility. But because they are on different lines, it will only randomly consider one of those, and therefore there will usually be no output. You need to put them all on the same line like this:

    [when] {$RC} = Iron bars [do] ConvoyHighPay [end][when] {$RC} = Hemp and Flax [do] ConvoyMediumPay[end]

    Personally, I wouldn't do that with When statements, you could do it with a dictionary table instead.

    Alternately, you could reference [@ConvoyPay{RC}] and then have tables for each payment type.

    I also wouldn't use a Set statement, since you don't seem to be using the variable anyway. Randomizing the value and then looking it up on the table seems redundant when you could go straight to the table. If you do need the value, you can assign it there:

    Table: RandomConvoyPay
    [RC==Iron bars][@ConvoyHighPay]
    [RC==Hemp and Flax][@ConvoyMediumPay]

  • Thank you both of you. I ended up doing something using both of your answers and it works now as I wanted it.

    Below is the entire code in case it provides some value to you to look at it.

    It's for a board game called "Pirates: Constructable Ship Game" in case anyone knows it. I wanted to have a kind of RPG, Mount&Blade-style extension to it, so this is it.

    I created a map of the Baltic Sea that I seperated into tiles and the distance from the port you are at to the one they ask you to take them to is factored in, in the pay calculation. (Every area has a label to it, that is what the A1-F8 codes are)
    The amount of ships in the convoy you accompany reduces the pay and the cargo they have loaded increases it.

    Travel Type is supposed to work as a general difficulty slider so that while you travel, traversing each area, you generate once on a seperate table to see what happens. The more valuable the cargo, the higher the chance a pirate group attacks. For bulk fish and potash convoys there is a special increased chance to attract a sea monster.

    The whole point of calling the Travel Types letters instead of "Dangerous" or "Calm" is that the player is supposed to figure out by themselves that transporting valuable cargo is going to attract more pirates and potentially other things.

  • Very cool!

Leave a Comment