console.log() is the best script!

Internetomancer

Veteran
Veteran
Joined
Nov 16, 2015
Messages
57
Reaction score
26
First Language
English
Primarily Uses
Hello!  :)


I'm pretty new here.  I just wanted to point out to other newbies the most useful newbie thing I've learned:


The console is [SIZE=12.8px]essential for:[/SIZE]


1) writing code.


2) debugging code


3) play-testing any game.


You can get to the console anytime while playing by pressing f8.
For now, I suggest you look at it in a Battle Test...


(Click on game database, then on troops, then at the top right there's the battle test button that let's you do pretend battles)


Then press f8 and there's the console.


You should see a > cursor where you can type things.


Type:      console.log($


At this point you'll see a little drop down list.


Some of the things on the list will begin $data; like $dataItems   or  $dataMonsters... these are permanent things in your database.


Other things will begin $game -- like $gameParty or $gameTroop or $gameVariables... these are things going on in your current game-- like who's in your party right now, and who are the monsters that you're fighting right now.


But for now, just go with.   console.log($gameTroop)   And press enter.  And don't forget to add the ")"  


You'll see something that looks like nonsense.

>Game_Troop {_inBattle: true, _interpreter: Game_Interpreter, _troopId: 1, _eventFlags: Object, _enemies: Array[4]…}
Now click on that line somewhere with your mouse...


And you'll get something like this:

Game_Troop {_inBattle: true, _interpreter: Game_Interpreter, _troopId: 1, _eventFlags: Object, _enemies: Array[4]…}


>_aiKnownElementRates: Object


>_enemies: Array[4]


>_eventFlags: Object


_inBattle: true


>_interpreter: Game_Interpreter


>_namesCount: Object


_troopId: 1


_turnCount: 0


__proto__: Game_Troop
Which still looks like nonsense....


But you'll notice a couple things--


_troopId: is the Id of the troop you're fighting.


_TurnCount is what turn it is.


Go ahead on click where it says  >enemies: Array[]


And again you'll get a drop down...

0: Game_Enemy


1: Game_Enemy


2: Game_Enemy
.


These are the enemies you're fighting right now.


Go ahead and click on one.

Game_Enemy


_actionState: "waiting"


_actions: Array[1]


_animations: Array[0]


_buffTurns: Array[8]


_buffs: Array[8]


_classId: 0


_cooldownTurns: Object_damagePopup: Array[0]


_effectType: null_enemyId: 8


_hidden: false


_hp: 100


_lastTargetIndex: 0


_letter: " A"


_level: 1....
And boom, a whole lot of details!!!  Including all the stats, and states, and everything!


Next, you can also skip the above steps if you type something like this:

console.log($gameTroop._enemies[0]._hp)
Basically, each time you want to dig deeper, just add a period, and then type in the next part.


(By the way, if you hit the up arrow, on an empty console box, you'll see the last thing you just typed.  Which is makes the whole typing thing go a lot faster!)


"Okay.. neat... but what do I do with this?"  I hear you say.


Well for one thing you can see some data that aren't visible to the player, like the monster MP.  


(also any $gameVariables, $gameSwitches, other variables, arrays, plugins, invisible states, etc. etc..  ie. anything funky you do behind the scenes.)


So if in your game, you hit a switch but you need to know if that switch is actually hit, this will tell you.


It's also a great first step to writing code, because now you know the names of all the variables!  
Anything you write in your console, you can also write in an event script.  And anything you write in an event script, can also be written in the console.  They both just execute code.


So for example if you type in the console (or an event script):

$gameTroop._enemies[0]._hp=5
The first enemy will suddenly have 5 hp.  Which is great if your sitting around punching an enemy and you want to get to the next part.


If you combine this with the most basic java script knowledge-- if(){}... for(){}.. you'll be able to do whatever you want!


[SIZE=12.8px]So for example, maybe you could add that to a common event script that runs every round, and now you get to know how much life your enemies have every round.[/SIZE]

for(var i = 0; i< $gameTroop._enemies.length; i++)  {


console.log($gameTroop._enemies._hp)


}
 


Now during a play-test you don't have to wait to the end of the battle to see how you're doing.


In other words-- with a tiny bit of scripting skill-- you can give yourself a sort of God Mode, allowing you to test everything in the game without having to slog through the whole game.
 
Last edited by a moderator:

bmwd Gaming

Villager
Member
Joined
Mar 16, 2016
Messages
9
Reaction score
0
First Language
English
Primarily Uses
I've heard of the console.log but never knew anything about it. I will have to play around with it and learn more on JavaScripting, but it definitively helps further my understand. Thank you for this.
 

Tenaar Feiri

Warper
Member
Joined
Apr 28, 2016
Messages
3
Reaction score
0
First Language
Norwegian
Primarily Uses
Thanks a lot for posting this!


This is going speed up learning to script for this engine a ton! Figuring out variables to target for specific things will become much easier!
 
Last edited by a moderator:

Crispy-Ghee

The Crispy One
Veteran
Joined
Apr 14, 2016
Messages
30
Reaction score
52
First Language
English
Primarily Uses
Thanks for the info! This is going to be super useful in really getting to understand the RPG Maker engine code. This is great
 

ACECORP

Founder & Entrepreneur
Veteran
Joined
Apr 6, 2016
Messages
253
Reaction score
39
First Language
English
Primarily Uses
RMMV
Does this also work for IOS exported games, by writing to the IOS Console? It would be great to be able to use a iPhone tool like iConsole to see RPGMMV errors and console messages in IOS. Very good for bug testing an IOS build.
 
Last edited by a moderator:

Skunk

Melody Master
Veteran
Joined
Mar 2, 2013
Messages
1,069
Reaction score
398
First Language
English/Slavic
Primarily Uses
RMMV
Does this also work for IOS exported games, by writing to the IOS Console? It would be great to be able to use a iPhone tool like iConsole to see RPGMMV errors and console messages in IOS. Very good for bug testing an IOS build.


This is intended only for during game development, and this is an ooold post.
"necro posting" is against forum rules.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,584
Latest member
Faustus2501
Top