dim3 Forum

Full Version: sending messages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The tutorial's direct instruction:
Code:
game.event.sendMessage(DIM3_MESSAGE_TO_PLAYER,'Player',123);

my script:
Code:
function gameChooserSelect(id)
{
    switch (id) {
    
        case CHOOSER_ITEM_MALE:
            game.event.sendMessage(DIM3_MESSAGE_TO_PLAYER,'player',980)
            return;
            
        case CHOOSER_ITEM_FEMALE:
            game.event.sendMessage(DIM3_MESSAGE_TO_PLAYER,'player',981)
            return;
                }
}

game is not defined.
You can only access game.* from within a game script (for example, your Game.js). Thankfully, the Event object is available to all course, object, weapon, and projectile objects as well. So, if you're working on an object object, use obj.event.sendMessage; use weap.event.sendMessage if you're scripting a weapon; and so on.
but it is in the game script:
Code:
// ***********************************************************
//
// Game Script
//
// This script is the main script for the entire game.
//
// ***********************************************************

// menu item ids

var MENU_ITEM_CONTINUE=0;
var MENU_ITEM_SETUP=2;
var MENU_ITEM_SAVE_LOAD=3;

var MENU_ITEM_SHOW_CONSOLE=10;
var MENU_ITEM_HIDE_CONSOLE=11;

var CHOOSER_ITEM_MALE=100;
var CHOOSER_ITEM_FEMALE=101;

//
// game startup
//

function gameConstruct(game)
{
        // set the scaling factor for the bitmaps
    
    iface.screen.widthScale=640;
    iface.screen.heightScale=480;
    
        // if not a network game, then set start map and
        // position, otherwise get that info from the host
        
    if (!map.setting.multiplayer)
        map.action.setMap('CT','Start','Player');
    else
        map.action.setHostMap();
}

//
// handle menu events
//
    
function gameMenuSelect(id)
{
    switch (id) {
    
        case MENU_ITEM_CONTINUE:
            return;
            
        case MENU_ITEM_SETUP:
            iface.interaction.startSetup();
            return;
            
        case MENU_ITEM_SAVE_LOAD:
            iface.interaction.startSaveLoad();
            return;
                        
        case MENU_ITEM_SHOW_CONSOLE:
            iface.console.show();
            return;

        case MENU_ITEM_HIDE_CONSOLE:
            iface.console.hide();
            return;
            
    }

}

//
// Handle game play join rules
// ------------------------------
// This event is called when a player is joinging.
// Here you would decide:
// 1) What team the player is going on by either letting
//    them use their team pick or placing them on a team.
// 2) What spots the player can spawn on.  The type will always
//    be "Spawn" and the name whatever is choosen.  If this is
//    not set, then the values in map.action.setMap() will be used.
//

function gameRuleJoin(game)
{
    var        redTeamCount,blueTeamCount;
    
    switch (game.join.name) {

            // no team for death match, and can
            // spawn on any spot with the type
            // "spawn"

        case 'DeathMatch':
            game.join.clearTeam();
            game.join.clearSpawnSpot();
            break;

            // team death matches leaves the team
            // the user selects and allows spanning
            // on any spot with type "spawn"

        case 'Team DeathMatch':
            game.join.setTeam(game.join.team);
            game.join.clearSpawnSpot();
            break;

            // Capture The Flag forces users to opposite
            // sides (by count) and picks team and spawn
            // points by color

        case 'CTF':
            redTeamCount=game.join.countTeam(DIM3_TEAM_RED);
            blueTeamCount=game.join.countTeam(DIM3_TEAM_BLUE);
            if (redTeamCount<blueTeamCount) {
                game.join.setTeam(DIM3_TEAM_RED);
                game.join.setSpawnSpot('Red');
            }
            else {
                game.join.setTeam(DIM3_TEAM_BLUE);
                game.join.setSpawnSpot('Blue');
            }
            break;

    }
}

//
// Handle game score rules
// -----------------------
// This event is called whenever a player scores some
// kind of 'point' (achieves a goal, gets a kill, etc.)
// The score is calculated based on game rules for the
// current game type.
//

function gameRuleScore(game)
{
    switch (game.join.name) {

        case 'CTF':
            game.score.setScore(game.score.goal);
            break;

        default:
            game.score.setScore(game.score.kill-game.score.suicide);
            break;
    }
}

//
// Handle Game Rules
// -----------------
// This event is called whenever the game needs a rule
// to be handled.  We use the subEvent to figure out which
// rule we need to deal with.
//

function gameRule(game,subEvent)
{
    switch (subEvent) {
    
        case DIM3_EVENT_RULE_JOIN:
            gameRuleJoin(game);
            break;

        case DIM3_EVENT_RULE_SCORE:
            gameRuleScore(game);
            break;

    }
}

function gameMessage(subEvent,id)
{
        // show map chooser is game_0
        
    if ((subEvent==DIM3_EVENT_MESSAGE_FROM_KEY_DOWN) && (id==0)) {
        iface.interaction.startChooser('Texture Chooser');
    }
}

function gameChooserSelect(id)
{
    switch (id) {
    
        case CHOOSER_ITEM_MALE:
            game.event.sendMessage(DIM3_MESSAGE_TO_PLAYER,'player',980)
            return;
            
        case CHOOSER_ITEM_FEMALE:
            game.event.sendMessage(DIM3_MESSAGE_TO_PLAYER,'player',981)
            return;
                }
}


//
// handle game events
//

function event(game,mainEvent,subEvent,id,tick)
{
    switch (mainEvent) {
    
        case DIM3_EVENT_CONSTRUCT:
            gameConstruct(game);
            return;
            
        case DIM3_EVENT_MENU:
            gameMenuSelect(id);
            return;

        case DIM3_EVENT_RULE:
            gameRule(game,subEvent);
            return;
            
        case DIM3_EVENT_MESSAGE:
            gameMessage(subEvent,id);
            return;
            
        case DIM3_EVENT_CHOOSER:
            gameChooserSelect(id);
            return;
            
    }
}
Code:
function gameChooserSelect(game,id)
{
    switch (id) {
    
        case CHOOSER_ITEM_MALE:
            game.event.sendMessage(DIM3_MESSAGE_TO_PLAYER,'player',980)
            return;
            
        case CHOOSER_ITEM_FEMALE:
            game.event.sendMessage(DIM3_MESSAGE_TO_PLAYER,'player',981)
            return;
                }
}


//
// handle game events
//

function event(game,mainEvent,subEvent,id,tick)
{
    switch (mainEvent) {
    
        case DIM3_EVENT_CONSTRUCT:
            gameConstruct(game);
            return;
            
        case DIM3_EVENT_MENU:
            gameMenuSelect(id);
            return;

        case DIM3_EVENT_RULE:
            gameRule(game,subEvent);
            return;
            
        case DIM3_EVENT_MESSAGE:
            gameMessage(subEvent,id);
            return;
            
        case DIM3_EVENT_CHOOSER:
            gameChooserSelect(game,id);
            return;
            
    }
}

Wink
oh, ok, thanks.
Code:
        case 4:
            if (DIM3_EVENT_MESSAGE_FROM_SCRIPT,'game',980){
                 obj.model.animation.hideMesh('Fdummy1')
                 obj.model.animation.showMesh('Mdummy1')
        }
          return;
                
            if (DIM3_EVENT_MESSAGE_FROM_SCRIPT,'game',981){
                 obj.model.animation.hideMesh('Mdummy1')
                 obj.model.animation.showMesh('Fdummy1')
        }
          return;
it's in the end of playerMessage. It doesn't throw an error, but it doesn't do anything.
(Forgive my idiocy, I've never done a successful message before)

[edity edit]

here's my data folder, stripped down to nothing but what is necessary to prevent major errors.

http://www.mediafire.com/?1jv1ye2yyti
Because you're looking for id==0 in your gameMessage() function, I'll assume you're relying on the game_0 Action (which is assigned to the Delete key) to open your chooser. So, you hit Delete and your chooser opens. You select the first option in the chooser, and your gameChooserSelect() function fires a message over to Player.js with the id of 980. This is where your first problem is encountered.

Code:
if (subEvent!=DIM3_EVENT_MESSAGE_FROM_KEY_DOWN) return;

This line immediately exits because the subEvent type is actually DIM3_EVENT_MESSAGE_FROM_SCRIPT. So you'll need a block of code something like this:

Code:
if( subEvent == DIM3_EVENT_MESSAGE_FROM_SCRIPT )
{
    switch( id )
    {
        case 980:
            obj.model.animation.hideMesh('Fdummy1');
            obj.model.animation.showMesh('Mdummy1');
            return;

        case 981:
            obj.model.animation.hideMesh('Mdummy1');
            obj.model.animation.showMesh('Fdummy1');
            return;
    }
}

After that, you should be able to change genders at the drop of a hat. Smile
OOOOOOO

thanks! it worked.

(are you really a new member?)
dimwit Wrote:(are you really a new member?)
Just because he is new to the forum, doesn't mean he never worked with Dim3 or JavaScript before, does it?
I have been working with Dim3 for 3 months before registering here and I had a little experience with JavaScript and coding in general before. Smile
dimwit Wrote:OOOOOOO

thanks! it worked.

(are you really a new member?)

You're quite welcome!

And, as Bink pointed out, I've been fiddling with Dim3 on and off for a couple of years and have a coding background. I just never registered in the forum until now. Smile
Reference URL's