Create account / Log in

Randomizing game piece images.

Talk about module design ideas and techniques.

Moderators: uckelman, Tim M

Randomizing game piece images.

Postby plloyd1010 » October 17th, 2013, 4:39 pm

I am playing around with my first modules. I am having trouble working out how to randomize some pieces.

The first problem, which is more for aesthetics, is randomizing the base image for an otherwise constant game piece. Specifically I have 3 counter images, all of which have the same combat factors. I would like to be able to get a counter and have one of those 3 images randomly assigned to piece in the game. There will usually be more than 3 of these pieces used, and they are double sided. I've tried creating a deck, but haven't been able to integrate it into the piece rendition.

The second problem is probably somewhat easier. I want create a stack of double sided pieces, draw one random piece, then get a random side (like a coin flip). I know I start with a randomized deck of the pieces, but don't know how to flip the piece. I am also not sure I know how to add the piece to the deck, but I should have that figured out later today.

Thanks
User avatar
plloyd1010
 
Posts: 23
Joined: October 17th, 2013, 4:25 pm

Re: Randomizing game piece images.

Postby DrNostromo » October 18th, 2013, 2:54 pm

Sounds like what you want to use is a Layer trait controlled by a Dynamic Property that is assigned randomly.

Ok, I'm assuming you're going to use 3 images.

Add a Dynamic Property to your piece. Give it a name like - ImageCode. Make it numeric with a range from 1 to 3.
Key Command - SetImageCode
Type - Set value directly
New value - $D3_result$

Add another Dynamic Property to your piece with the name - ImageSet. Make it numeric with a range from 0 to 1 with a starting value of 0.
KeyCommand - ImageLock
Type - Set value directly
New value - 1

Add a Layer trait
Check Always active
Uncheck Loop through levels
Check Level follows expression value
Follow Expression - ImageCode
Add your images as layers 1, 2, 3

Add a Global Hotkey trait
Keyboard Command - GetD3Roll
Global Hotkey - RollD3

Add a Trigger Action trait
Trigger when properties match - ImageSet = 0
Keyboard command - MapSwitch
Perform these keystrokes
GetD3Roll
ImageLock
SetImageCode

In the Map Window properties at the bottom, you find:
Key Command to apply to all units ending movement on this map - MapSwitch

Add a Dice Button to your main Vassal tree
Name - D3
Leave Button Text, Tooltip Text, and Button Icon blank
Number of dice - 1
Number of side per die - 3
Add to each die - 0
Add to overall total - 0
Check Report Total
Hotkey - RollD3
Uncheck - Prompt for values

Now, when a piece is moved to the map, the key command MapSwitch will be triggered. Your trigger action trait will roll a D3 and set that value as the ImageCode. Your layer trait will then display the image assigned to that code. It will also set the ImageSet variable to 1 so that the image won't change every time you move the piece as trigger action will only work if ImageSet is set to 0.

Does that work?
User avatar
DrNostromo
 
Posts: 1061
Joined: December 21st, 2007, 3:54 am
Location: Wine Country, Cal. USA

Re: Randomizing game piece images.

Postby tar » October 18th, 2013, 7:10 pm

On Thu, Oct 17, 2013 at 9:40 AM, plloyd1010 wrote:
>
> The second problem is probably somewhat easier. I want create a stack of
> double sided pieces, draw one random piece, then get a random side (like
> a coin flip). I know I start with a randomized deck of the pieces, but
> don't know how to flip the piece.
>

Well rather than get a random side, you could just double the number of
pieces in the deck.

What you would do is to have your pieces with
Piece 1: Side A / Side B
Piece 2: Side A / Side B
Piece 3: Side A / Side B
and then just add
Piece 1a: Side B / Side A
Piece 2a: Side B / Side A
Piece 3a: Side B / Side A

then what you draw is already what you want.
(I assume you will still want to be able to flip the drawn pieces between
side A and B. If you don't need that, it becomes even easier.)
User avatar
tar
 
Posts: 776
Joined: January 2nd, 2008, 6:53 pm
Location: Los Angeles area

Re: Randomizing game piece images.

Postby plloyd1010 » October 19th, 2013, 3:00 pm

I tried yoru code Dr_Nostromo. It does create the piece, but the image on the piece isn't changing. Specifically it always has the first image. I rearranged the order of the traits a couple times to adjust the process order with out success. It seems that I am either never get a number other than 1 out of the D3 (I always draw at least 5 units for a test), or it isn't being applied. The only feedback I get is "piece created off-board".

I don't suppose there is a debug mode for VASSAL? I'll mess with it some more today.
User avatar
plloyd1010
 
Posts: 23
Joined: October 17th, 2013, 4:25 pm

Re: Randomizing game piece images.

Postby plloyd1010 » October 19th, 2013, 3:10 pm

tar, that wouldn't work. Referring to your suggestion, if I pulled out piece 1b, piece 1a is still in the mix. The game I am working on is a module for Panzer Grenadier. The idea is that every leader drawn eliminates 2 possibilities. Now if there is a way to draw a random counter (presume 1a/1b), and have its counterpart (1b/1a) dropped from the mix, your idea would work.
User avatar
plloyd1010
 
Posts: 23
Joined: October 17th, 2013, 4:25 pm

Re: Randomizing game piece images.

Postby DrNostromo » October 21st, 2013, 2:42 pm

Here's a sample. Just change the .zip to .vmod

When you run, you'll have a deck of 5 pieces. As you move the pieces to another part of the map, it will set the image.
Attachments
RandomImage.zip
(24.73 KiB) Downloaded 136 times
User avatar
DrNostromo
 
Posts: 1061
Joined: December 21st, 2007, 3:54 am
Location: Wine Country, Cal. USA

Re: Randomizing game piece images.

Postby plloyd1010 » August 14th, 2014, 1:41 pm

I did eventually get this to work in my game. The critical bit of information you left out was that when the piece is drawn, it need to be placed on the same map as the deck. Otherwise it never does the mapswitch command and only puts up the first layer.

It works pretty well now. Thank you.
User avatar
plloyd1010
 
Posts: 23
Joined: October 17th, 2013, 4:25 pm


Return to Module Design

Who is online

Users browsing this forum: Google [Bot] and 3 guests