Fighting with Mechanics

 Arrays an sorting art Javascript 101... or 102.. as mentioned to me on programming forums. I unfortunately skipped that class. So Javascript is a little un-intuitive to me. Which is fine I LOVE a puzzle. 

For a section of the game, i need to have a Pageant. This will be a performance challenge mini-game and a judging of your Drag. This means judging on Makeup, Outfit and Hairstyling. There will be five contestants. 4 NPCS (which will most likely be the mentors you have met in the start) and you the player as contestant 5. 

Once the pageant is over, your mini-game score is added to the Drag score to make the final score. Then the contestant's names are called out in order from first place to last.

This to me sounded simple. SO i deep dove on Google finding bits of open source code to help me Frankenstein a possible solution. After some testing, I managed to get it working except I forgot one word in the program which was a simple overstep. 

The program adds the scores together into scor1 - 5. Then calls it into an array with the contestant's name. Once it calls it, the program orders the numbers with names from highest to lowest. Then we call the names out in a simple text message. It finally does a check to see if you won or not.

Hopefully, the code may help someone out in the future

Here is what the code looks like. 






var act = $gameActors._data;

var numbers = [{name: 'cleo', score: $gameVariables.value(42)},{name: 'toxxic', score: $gameVariables.value(43)},{name: 'katarina', score: $gameVariables.value(44)},{name: 'jax', score: $gameVariables.value(45)},{name: $gameActors.actor(1)._name, score: $gameVariables.value(46)}];

numbers.sort((a, b) => b.score - a.score);

$gameVariables.setValue(100, numbers[0].name);

$gameVariables.setValue(101, numbers[1].name);

$gameVariables.setValue(102, numbers[2].name);

$gameVariables.setValue(103, numbers[3].name);

$gameVariables.setValue(104, numbers[4].name);


Here's what the test looks like, now to make it look pretty.






Comments

Popular Posts