Page 1 of 1

Chat help requested

Posted: Thu Sep 13, 2007 3:51 pm
by SunTzu
If I only want to send a chat once per Lux session, where would I put it?

I tried it in Defender(), but Lux won't load the bot then. I also tried it setPrefs, but I didn't want the chat sent at the beginning of every game.

Posted: Thu Sep 13, 2007 3:59 pm
by RandomGuy
can you send it in setprefs and then store a value in persistent storage that the chat message was sent? Then you could check the value in storage before sending (it would skip it all future games) until lux was restarted...

Posted: Thu Sep 13, 2007 6:03 pm
by Bertrand
Do you know about static variables? Only one instance exists for the class, and it will remain for the whole lux session.

Declare a global static like this:

static boolean helpMsg = false;

Then, somewhere in placeArmies(), insert this code:

Code: Select all

        if (!helpMsg)
        {
            helpMsg = true;
            board.sendChat("Read this human, or else.");
        }
 
The message will be issued once per session, even if multiple copies of the AI are playing.

Posted: Thu Sep 13, 2007 8:13 pm
by SunTzu
Thanks! I'll give that a try Bertrand.

RandomGuy's suggestion would have worked if persistent storage didn't work across multiple sessions.

Posted: Thu Sep 13, 2007 8:36 pm
by RandomGuy
Good to know - I thought that Lux reset those values at each startup.

Posted: Fri Sep 14, 2007 12:31 am
by guest
Sure thats why you store a date & time in the persistant store.