Game Variables

Tips and Tricks on Events, Economy, etc.
User avatar
Wolverine@MSU
CEO
Posts: 1166
Joined: Fri Nov 10, 2006 2:14 pm
Location: East Lansing, MI

Unread post

Wolverine wrote:If a different number is generated for each test, the event should fire 25% of the time (0.5 x 0.5)
Gwizz wrote: If both random generators can fire, then the event can be both true and false at the same time. This is not possible.
Since the two tests are "AND"ed together, both have to be true in order for the event to trigger.
Gwizz wrote: Even adding the ramdom numbers makes it possible for a zero to take place. Zeros don't work with random numbers, not as we use them. Now a 1 could have been programed into the mix if a zero appeared.
I'm not sure whether the random number generator will ever return a zero. I think it rounds up to the next whole number. That one is easily testable: Random 1-100 < 1, and see if it ever triggers
Gwizz
CEO
Posts: 1100
Joined: Sat Nov 11, 2006 6:45 pm

Unread post

I'm not sure whether the random number generator will ever return a zero. I think it rounds up to the next whole number. That one is easily testable: Random 1-100 < 1, and see if it ever triggers

I believe a random Generator can only give a number where 1 is the lowest number, 1-100, 1-1000. But if two results are possible, I can see how the two numbers one false and one positive could be combined proportionally and some added mechanism used to remove a zero

I think it was one of the developers at Pop Top for RT2 that said, that once an element of an event tests true, the rest of the triggers in the same event turn off. Or some thing to that affect.

Now RT3 could be different. I wish I knew for sure.

Since the two tests are "AND"ed together, both have to be true in order for the event to trigger.

again I agree, that is standard math

I still keep wondering why my events worked, if events work using standard math.
User avatar
wsherrick
Engineer
Posts: 584
Joined: Sun Nov 12, 2006 12:38 am
Location: New Hope, Pennsylvania

Unread post

The way I set up those random variables were fairly simple in my mind. I have 6 separate random events that occur within one event (the Commodities Market) I used random # 1-100 for all six events. the random numbers are set up number> and <number is to limit the choice between the higher and lower number for that specific event. If you look at all 6 events-all the numbers 1 thru 100 are accounted for. I had to make so that only one event would fire each year, so I had to make them all mutually exclusive to each other. If I had two events with numbers like say; random 1-100>50 and another that read random number blah, blah >75, there is a good chance that both events would fire at the same time. So I had to divide them up so that wouldn't happen.
Back to Hawk's earlier question about setting the CV=10. Yes, that stops the whole shebang from running again. Setting the CV=0 would also work, but I set it to 10 to make sure I didn't accidentally interfere with an earlier event using similar variables.
Gwizz
CEO
Posts: 1100
Joined: Sat Nov 11, 2006 6:45 pm

Unread post

If the and is used, I would think this ties the variables together. (Normal Math)
If no and (or any other connector is used, then the first random to fire, stops any other from firing.

The thing I was hung up on is this:

Random1-100>50 and Random1-100<60.
Therefore any number 51 to 59 would fire true.

Reversing the >< to <>,

Random1-100<50 and Random1-100 >60.
Therefore any number 50 to 60 would fire False.
Therefore any number 1-49 or 61-100 would fire true.
Say the first Random number is 10 which fires true
but this is connected by the and to the 2nd random.
So the 2nd random has to test and says the number is 10 which fires false.

So we have an event that fires both true and false.
Does true rule? I would think so. It fired first.
Or, if we have the reverse.
The first random tests false and the 2nd tests true.
Does the false rule. I think the answer is that true rules.
But I can't say why since they are both connected by AND

I don't think there is a disagreement on the results just on the mechanism for how it works in RT3. I'm not sure there is even a disagreement on mechanism.

Trying to explain the mechism can be confusing since it is a part of code where we can only guess at how it works. We can test, but, because of the randomness of the numbers they will always be suspect. But the bigger the test the better the chance of a correct answer. Wolverine's test seems to have thrown cold water on PopTops answer for how the mechanism works.
User avatar
Hawk
The Big Dawg
Posts: 6504
Joined: Fri Nov 10, 2006 10:28 am
Location: North Georgia - USA

Unread post

This is starting to get interesting.
Hawk
User avatar
wsherrick
Engineer
Posts: 584
Joined: Sun Nov 12, 2006 12:38 am
Location: New Hope, Pennsylvania

Unread post

It's propositional logic, which I made an A in while in college. An example being, IF your dog is out in the back yard AND it is raining THEN your dog will get wet. The first two statements must be true for the last statement to be true. If one of the first statements is found false then the whole thing is false. So IF the random number set with the >< it will only be true if the number is between the low and high values. Translation; IF the number is greater than 40 AND less than 60 THEN the event is true. IF they are set up like this <> then all the numbers on the OUTSIDE of the set values could indeed be found true, BUT since the roulette wheel stops spinning once the ball falls into one slot that is true, all the other number possibilities are no longer relevant until it is time for them to spin again. But it is possible to set up a random event whereby one number makes two things true at the same time, and that would screw up the works.
Last edited by wsherrick on Thu Dec 20, 2007 6:18 pm, edited 1 time in total.
User avatar
WPandP
Engineer
Posts: 762
Joined: Tue Sep 11, 2007 5:16 pm
Location: Cincinnati, Ohio
Contact:

Unread post

I thought it was pretty straightforward - the test confirmed 50% probability X 50% probability = 25% results. If you use AND to tie two conditions together, then they must both result in TRUE, or the event doesn't fire. If you tie them together with OR, then only one of them must result in TRUE in order for the event to fire.

Random1-100<50 AND Random1-100>60 = ALWAYS FALSE (if only one random number is being tested twice)
Random1-100<50 OR Random1-100>60 = TRUE for all numbers but 50 to 60 (if only one random number is being tested twice).

Of course, this is assuming that each Random call does not generate a new number, in other words that the same number is being used for comparison in both conditions. What has been hypothesized, though, is that each Random number condition becomes a new "roll of the dice" as it were, and thus it would be possible for the ALWAYS FALSE pair of conditions I listed above to actually result in TRUE some of the time.

THIS IS WHAT WOLVERINE'S TEST PROVED, that two Random Conditions must generate two diferent random numbers, and the use of "AND" requires that they both yield TRUE results in order for the event to fire. Use of "OR" would require only one of them to fire the event.

So, what is really happening:
Random1-100<50 AND Random1-100>60
= 50% TRUE AND 40% TRUE
= 0.5 x 0.4 = 0.2
This event should fire about 20% of the time. To write it as an example with sample numbers:
(Random1-100=36)<50 AND (Random1-100=84)>60 both conditions test true, thus event fires.
=Winchester, Paston & Portsmouth=
====== We Provide Pride! ======
User avatar
wsherrick
Engineer
Posts: 584
Joined: Sun Nov 12, 2006 12:38 am
Location: New Hope, Pennsylvania

Unread post

Yes you are right. The soundness of the set up has nothing to do with probabilities. The use of or is translated, "either or." Either you bring your dog in from the back yard while it is raining OR it will get wet. Either one number is true or the other one is. They are mutially exclusive of each other. That makes possible to make two different values yield a true result, but they both can't be true at the same time. Example, you can escape a burning building by going out of the door or out of the window, but you can't go out of the door and window at the same time.
User avatar
WPandP
Engineer
Posts: 762
Joined: Tue Sep 11, 2007 5:16 pm
Location: Cincinnati, Ohio
Contact:

Unread post

wsherrick-

Hey, I'm an architect! I bet I can find a way to go out of a door and a window at the same time... :D
=Winchester, Paston & Portsmouth=
====== We Provide Pride! ======
User avatar
wsherrick
Engineer
Posts: 584
Joined: Sun Nov 12, 2006 12:38 am
Location: New Hope, Pennsylvania

Unread post

As smart as you are, I'm sure you could. But how much would that cost the contractor? :lol:
User avatar
Hawk
The Big Dawg
Posts: 6504
Joined: Fri Nov 10, 2006 10:28 am
Location: North Georgia - USA

Unread post

All this discussion of whether the AND statement used in conjunction with two random variables, I wonder if this is relevant to this situation-found in the read me of the 1.06 patch.
Adds support for variable operands. In other words, you can now add a variable to
another variable.
Hawk
User avatar
WPandP
Engineer
Posts: 762
Joined: Tue Sep 11, 2007 5:16 pm
Location: Cincinnati, Ohio
Contact:

Unread post

Hawk,

"Variable operands" means arithmetic using the Game/Company/Territory variables. It doesn't necessarily have anything to do with Random number generation, BUT it could make the event scripting a little more meaningful in some ways. For instance, you might do a Random check against the sum of two variables:

(Random1-100)<(GV1+GV2)

This would let you have other events which involve trade-off choices, say, in which maybe you don't alter GV1 much, but the things you do impact GV2 significantly, increasing your chance of firing the above event. You might do other more complex calculations, too, such that GV1 and GV2 don't really have the same weight - maybe the things you do that affect GV1 are weighted more heavily because they are more likely to cause this random event to fire.

This does not involve the AND conjunction at all - the variables are added together within a single condition. You could still AND the above condition to another, such as:

(GV2-GV1)>10

... which would check to see that GV2 is the larger of the two variables and that it is higher by at least 10. This would in effect be another way of weighting the variables, I guess. "Variable Operands" is what enables the first part of the condition.

This is just an example! The second condition can be anything; my point is that "AND" and "Variable Operands" are just very different things.
=Winchester, Paston & Portsmouth=
====== We Provide Pride! ======
User avatar
Hawk
The Big Dawg
Posts: 6504
Joined: Fri Nov 10, 2006 10:28 am
Location: North Georgia - USA

Unread post

Well, it was a thought. I still don't understand all this stuff but I thought that might have something to do with it.
Thanks for the explanation. :D
Hawk
User avatar
ChrisW
Watchman
Posts: 53
Joined: Sat Sep 15, 2007 11:20 pm

Unread post

Thanks to Wolverine's elegantly-designed test, it seems pretty clear that the condition IF RANDOM1-100 > x AND RANDOM1-100 < y must use two different randomly-generated numbers. Granted, his test had the less-then/greater-than operators in the reverse order, but if the RT3 designers set it up so that it behaves differently depending on the order of the operators, they'd be setting things up for massive confusion on the part of scenario designers and all kinds of bugs. So I strongly doubt they did that.

If you really want to set up a test where the same random number is used both times, though, I'd think you could assign it to a variable. I don't know the exact syntax RT3 uses, but something like:

variable = RANDOM1-100
IF variable > 20 AND variable < 30

would have the effect of "generate one random number; if it has a value from 21 to 29, do this", which I think is the sort of thing Gwizz was trying to do.
User avatar
Markman
Cat
Posts: 8
Joined: Fri Feb 01, 2008 3:50 pm
Location: SC

Re: Game Variables Unread post

My observation is that you sometimes need to use variables because you can test for certain things, like Territories affected, in the Conditions... but not use them in Effects!

Or, here's another illustration: When I wanted to check how much rice was hauled out of a certain territory, I couldn't use it directly in the Status event (for checking how you're doing against the game requirements at the end of the year). The Status printout allows you to incorporate "LTD Rice hauled from Territory" as a field, but since you can't specify WHICH territory, you first need to set up an event to test Rice haulage against the chosen Territory, then set one of the variables equal to that amount. The variables (Game, Company, Player, Territory) can be called in the Status without a qualifier.
________________________________________
- Mark
User avatar
Wolverine@MSU
CEO
Posts: 1166
Joined: Fri Nov 10, 2006 2:14 pm
Location: East Lansing, MI

Re: Game Variables Unread post

I think you can use it directly in a Status Event, if you set up the trigger conditions to "Test against Territories", and select the correct territory in the dropdown box.. If you want to check "LTD Company Hauled Rice from Territory", you probably need to test against companies too, and select the Onscreen Player's Company.
User avatar
nedfumpkin
CEO
Posts: 2163
Joined: Sat Feb 16, 2008 9:16 pm
Location: Hamilton - Canada

Re: Game Variables Unread post

Game variables. If ever you wondered what you were learning algebra for in grade 9, then you will have some difficulty with game variables. I personally love them and really started using them in New France. The initial work that I was doing in my Atlantis map (before my computer stopped loading the game and put a halt to all development) was building on the usage of game variables.

Game variables allow you to have choices with direct and indirect consequences in the game, for me that is the coolest thing. If you add in random numbers then you can really make things interesting. Every thing pretty much hangs on the if statement. If a=b, then c, or else d. Nest those babies and you can program pretty much any conditions into the game.
Gwizz
CEO
Posts: 1100
Joined: Sat Nov 11, 2006 6:45 pm

Re: Game Variables Unread post

While trying to find an unread thread, I stopped here.

One more comment. A random number generator can be what ever you want it to be. for example, The normal random number is 1:1000. One chance in 1000.
You could use 1:2 which would give you a 50/50 chance that the trigger would test either true or false. This works in RRT2 and I assume it is the same in RRT3.

This post will also test my orange light to see if it will turn off.
User avatar
Sugus
Engineer
Posts: 569
Joined: Wed Feb 04, 2009 1:33 pm
Location: Rorschacherberg, Switzerland

Re: Game Variables Unread post

I dont know if there's an overview concerning game variables at another place within this forum. So - I'll present my modest knowledge here:

There are exactly four territory variables for each territory used,
there are exactly four company variables for each company used,
there are exactly four player variables for each player used,
but there are only four game variables at all.

The latter one are most simply to use, because when using the other ones you always have to specify "force test against ..." in the right way. Besides that, any variable may hold any value you want and you can do value assignments (e.g. random numbers) and limited arithmetics. It's up to you to do something reasonable with them :idea: ...

Also, you should be careful when choosing a variable, if you want to present it's value within the status or a newspaper - they may not all being formattable as you like. I found that the game variables, the company variables as well as territory variables 2 and 3 allow different presentations (numeric, money, boolean [e.g. true or false], connected and completed), whereas the remaining ones only appear as number.


@Markman: If you want to present e.g. the "number of loads of rice hauled from territory Xyz" as part of the status, you simply have to create a separate status event and specify "force test against territories", so that you can choose the one you need. I did this twice in my 'Rorschach-Heiden Mountain Railroad' concerning "beer from Rorschach" and "meat to Heiden".


BTW - as a programming mathematician I enjoyed the discussions above concerning random numbers!
There's no business like RT business ...
low_grade
Dispatcher
Posts: 438
Joined: Sun May 17, 2009 3:02 pm
Location: Cleveland, OH

Re: Game Variables Unread post

Programming mathematician! I'm jealous! I dream of cybernetic economies, but I'm too satisfied with RT III to do anything about it...

On a serious note, I wanted to add my two bits on variables.

You can do fairly complex calculations, but only one step at a time. For example, I wanted an event to subtract 10% of company ytd profit from company cash once profit is over $5M, and used the following two events to do it:

1. [Conditions] Check at end of year. Force check company (not sure if I needed that). [Effects] Set CV1=Company YTD profit. CV1 / 10.

2. [Conditions] Check at end of year. Force company check. Check Company YTD Profit >= $5M. [Effects] Set Company Cash - CV1.

You can't just do one statement to get 10% of YTD Profit. First statement is what you set the variable to initially, second statement is division by 10. If I wanted to add a deductible I could add a third statement of minus $100K or something. Point is, you can have complex calculations, but they need to be broken down to one step at a time, in the right order. So if instead of a deductible I wanted to reduce taxable income (which without a progressive tax structure amounts to the same thing, but anyway..) then I would move statement 2 into a third position and insert a new statement 2 of CV minus $1M or something.
Post Reply