dim3 Forum

Full Version: Transformation problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Ive made a code that will allow the player to transform into a tree, but it doesnt work, heres the code, can anyone tell me why?

Code:
        case 4:        
                  if (!model.animation.showOnlyMesh('Evolve1')) {
                model.animation.showOnlyMesh('Evolve1');
                obj.setting.inputMode=DIM3_INPUT_MODE_FPP;
                obj.motionVector.alterGravity(2000);    
                iface.console.write('Dumb Tree');
            }
            else {
                model.animation.showOnlyMesh('Default');
                obj.setting.inputMode=DIM3_INPUT_MODE_FPP;
                iface.console.write('No Dumb Tree');

            }
            return;

and here is the code for the key
Code:
<Action name="player_4" attach_0="P" />

and the consol doesnt detect a problem, wich is odd...
Sad
It's because when you type the following you're asking the engine if the returned value is false. Remember how saying "if (blrog != florg)" means "if blorg [not equal] florg"? Think of ! in front of anything as "not". So "if (!function())" would be "if ([not]function())" or "if ([return value is false]function()".

Code:
if (!model.animation.showOnlyMesh('Evolve1')) {

In the case of what you wrote, as long as the mesh "Evolve1" exists and the function is executed then it will return true, meaning it will execute the "else" and turn the mesh to "Default". Instead of comparing the output of a function that changes the mesh, try comparing the mesh name its self. To do this, first set a variable that corresponds to the mesh that is first the player. In this case, the "Default" mesh. Find where that is set and add this below it:

Code:
var current_mesh = "Default";

Now in your function compare "current_mesh". Remember to change "current_mesh" to "Evolve1" when you change the mesh!

Code:
Code:
        case 4:        
                  if (current_mesh == "Default") { // Remember, == is comparison and = is assignement, so always use == in a comparison statement like 'if'
                model.animation.showOnlyMesh('Evolve1');
                obj.setting.inputMode=DIM3_INPUT_MODE_FPP;
                obj.motionVector.alterGravity(2000);    
                iface.console.write('Dumb Tree');
                current_mesh = "Evolve1";
            }
            else {
                model.animation.showOnlyMesh('Default');
                obj.setting.inputMode=DIM3_INPUT_MODE_FPP;
                iface.console.write('No Dumb Tree');
                current_mesh = "Default";
            }
            return;
teh1ghool Wrote:In the case of what you wrote, as long as the mesh "Evolve1" exists and the function is executed then it will return true, meaning it will execute the "else" and turn the mesh to "Default". Instead of comparing the output of a function that changes the mesh, try comparing the mesh name its self. To do this, first set a variable that corresponds to the mesh that is first the player. In this case, the "Default" mesh. Find where that is set and add this below it:

Code:
var current_mesh = "Default";

I checked like, a thousand times, and there is no place that sets the "Default" mesh in player.js, so either its not in player.js, or i need to add a function to set the default mesh. There is a place to set the model, but not the mesh.
i need enlightenmint Rolleyes
There has to be one. In the standard player script, there's a line that shows only the default mesh. I'm 110% sure that it's there.
Just set
Code:
var current_mesh = "Default";
at the top of the script and use the function teh1ghool gave you to change meshes.
im sorry... but as you probaly know, im a complete newb at scripting. i can script, but i dont know what to script. any suggestions on how to make the transform function? Rolleyes
teh1ghool already explained it, didn't he? O_o
I'll explain it again, in a way that's hopefully easier to understand.

First create a variable that keeps track of the transformation state. Add this before the construct function:
Code:
var transformed = false;
This creates a new variable called "transformed" and sets it to false (because the player starts non-transformed).

Then create a new function like this:
Code:
function transformPlayer(obj) {
    if(transformed) { //if the player has already transformed
        obj.model.animation.showOnlyMesh('Default'); //show the default mesh
        transformed = false; //not transformed anymore
        //you can also add more stuff here that should be done when un-transforming
    } else { //otherwise (he has not transformed)
        obj.model.animation.showOnlyMesh('Evolve1'); //show the transformation mesh
        transformed = true; //now transformed
        //you can also add more stuff here that should be done when transforming
    }
}
and call this function when the right key is pressed, just like you did before:
Code:
case 4:      
    transformPlayer(obj);
    return;
That should do.
Though if you eventually want to have a bunch of different transformations, my method is more compatible. Smile
Thanks bink, your was less confusing then teh1gools, but thank you teh1gool anyway. Smile
this should become a tutorial.

EDIT:
this is going to be like a easter egg.
If it's an easter egg, make it harder to find. Try making it so that when you type a few letters it does it, usually you want the three letters to be a joke about the easter egg. And if the player transforms into a tree, make sure it's obvious that it's not some kind of glitch!
Yes Ccccc, i wanted that, but how would it be accomplished?
Pages: 1 2
Reference URL's