Newbie coding

Ok Im taking a stab here on custom class using an example I had from Tom D.

Is this ok so far and am I on right track? My java kung pow is quite weak, but I think I get whats going on (with this at least)…:slight_smile:

Feel free to rip if I’m doing this in a difficult manner. I’ve only done the first generated variable so far. Eclipse tells me I have 5 problems but the first four come from it not being in Vassal yet I think. The 5th (line 64) is the one irking me right now - should it? And is any of my enclosing incorrect?

java txt file in zip

What is the error you’re getting?

On 29/02/2008, Tim M <messages@forums.vassalengine.org (messages@forums.vassalengine.org)> wrote:

Post generated using Mail2Forum (mail2forum.com)

It is telling me the method getMapboard is undefined…hmm thought I followed example exactly

From: messages-bounces@forums.vassalengine.org [mailto:messages-bounces@forums.vassalengine.org] On Behalf Of Michael Kiefte
Sent: Friday, February 29, 2008 8:42 PM
To: VASSAL Engine Forums Mailing List
Subject: Re: [Developers]Newbie coding

What is the error you’re getting?
On 29/02/2008, Tim M <messages@forums.vassalengine.org (messages@forums.vassalengine.org)> wrote:
Ok Im taking a stab here on custom class using an example I had from Tom D.

Is this ok so far and am I on right track? My java kung pow is quite weak, but I think I get whats going on (with this at least)…:slight_smile:

Feel free to rip if I’m doing this in a difficult manner. I’ve only done the first generated variable so far. Eclipse tells me I have 5 problems but the first four come from it not being in Vassal yet I think. The 5th (line 64) is the one irking me right now - should it? And is any of my enclosing incorrect?

java txt file in zip

Post generated using Mail2Forum (mail2forum.com)

Tim,

My guess is that the example is so ancient that the method getMapboard no longer exists in whatever object you are trying to call it in. A quick source search reveals no method name getMapboard in any Vassal source module.

Looking at your source, I would guess getMapboard() should be a method of RSG and should look something like:

protected String getMapboard() {
return mapboards[mapboard];
}

Regards,
Brent.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thanks Brent,
that worked, I went back and looked at my the example code and found it was implemented there - slightly different and buried - either way though :slight_smile:

Moving along - I plow on albeit slowly and things are slowly getting clearer
I’ve now finished all my regular generated variables and fixed all my errors so far :slight_smile: (Still have one in main but not worried about it right now)

I now also generate a variable that references one of the regular previous variables and uses a random number to get its result (I hope - please check and let me know if I did this right with all the if/else stuff).

My next problem is I dont have an example how to cross-reference two regular variables and looking at these two variables plus a random number thrown in get a resultant variable. I think it would be similar in structure to my single reference/random number variable result. Am I correct?

Ive attached progress so far and spreadsheet of what Im trying to implement. Ive already done tables 1 - 4, Im now at table 5, 6 & 7

Hi Tim,

A couple of comments below,

Regards,
Brent.

*********** REPLY SEPARATOR ***********

On 1/03/2008 at 8:24 AM Tim M wrote:

Your selection for table 3 is not right. Your spreadsheet says the roll should be 2d6, but you are rolling 1d11 and selecting from the table instead. That’s why there are only 11 entries in the table, not 12 - You cannot roll a 1 with 2d6.

This:

private int generateAxisside() {
return randGen.nextInt(6) + randGen.nextInt(6);
}

will give the correct result of a random number selected from 0 to 10 (i.e. 11 different numbers) with the correct distribution.

or even better

private int generateAxisside() {
return roll2die();
}

private int roll2die() {
return randGen.nextInt(6) + randGen.nextInt(6);
}

because you will need the roll2die later.

You don’t need those big switch statements to set a variable to one less than another variable, I would just keep everything as numbers 0 up,

private int generateMapboard() {
return randGen.nextInt(28);
}

and just generate the mapboard name on the fly. Adding an integer to a string appends the string representation of the integer to the string:

public String getMapboard() {
return "Board " + (mapboard+1);
}

Then you can get rid of that array of board names also.

Encoding and looking up table data can be quite a challenge. The easiest way for you will be to encode everything as arrays. for example

final static final int[] TABLE4A = new int[] {1939, 1943, 1940, 1945, 1941, 1942, 1943, 1944, 1944, 1944, 1944};

Then all you have to do it

year = TABLE4A[roll2die()];

For table 5, you can set up 1 array for each column of each table, then do a switch on year:

if (axisPlayer.equals(“German”)) {
switch (year) {
case 1939: alliedPlayer = TABLE5A_39[roll2die()]; break;
case 1940: alliedPlayer = TABLE5A_40[roll2die()]; break;
etc.
}

If your really clever, you can set this up as a 2 dimensional array and use [year-1939] as an index into the array.

Just some ideas to keep you moving
Regards,
Brent.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Those tips you gave really helped Brent - made things a lot easier

Ive now got all the tables in, a bit of reformatting for readability and for the mosdt part it looks good.

I still seem to have an issue though stemming from table 3 & 4 (Axis Side and Axis year) which propogates through tables 5-7 but not sure why as I followed the hints.

Apart from that (ironing out table calls), the rand and main class are very incomplete. I know it is set up to echo in chat window, but what I’d really like to do is tie this into symbolic dice instead if possible but really dont know what to do here.

Anyways some one let me know what my table problems are so I can at least fix those up :slight_smile:

Almost done :slight_smile:

I have fixed everything including the main and rand class.
Im sticking with chat window first - Ill tackle linking symbolic dice after once I get it running.
I only have one problem though.

I have 2 integers GYear and IYear that I wish to read to set a string Year.
Ive tried this

public String getYear() {string Year = “”;
if (axisplayer.equals(“German”)) {
return "Year is " + (GYear);}
else {
return "Year is " + (IYear);}
}

and it doesnt like this saying it cant resolve GYear or IYear even though they are being resolved all over the place except here - what am I doing wrong?

well found my problem - letter capitalization :unamused:

So I’ve compiled and added it in to the mod and it works!!
Well sort of…
its a bit rough which ill fix up, and one variable is only partly showing up in chat (strange…).
Also my button icon does not seem to like the label Ive put in - just shows a little square in toolbar