じ☆ve冰风 发表于 6 天前

console.log() is the best script!

Hello! 
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7


                                        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 essential for:


                                        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…}                
Click to expand...


                                        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…}


                                                        >_aiKnownElementRates: Object


                                                        >_enemies: Array


                                                        >_eventFlags: Object


                                                        _inBattle: true


                                                        >_interpreter: Game_Interpreter


                                                        >_namesCount: Object


                                                        _troopId: 1


                                                        _turnCount: 0


                                                        __proto__: Game_Troop                
Click to expand...


                                        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                
Click to expand...


                                        .


                                        These are the enemies you're fighting right now.


                                        Go ahead and click on one.

                        Game_Enemy


                                                        _actionState: "waiting"


                                                        _actions: Array


                                                        _animations: Array


                                                        _buffTurns: Array


                                                        _buffs: Array


                                                        _classId: 0


                                                        _cooldownTurns: Object_damagePopup: Array


                                                        _effectType: null_enemyId: 8


                                                        _hidden: false


                                                        _hp: 100


                                                        _lastTargetIndex: 0


                                                        _letter: " A"


                                                        _level: 1....                
Click to expand...


                                        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._hp)                
Click to expand...


                                        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._hp=5                
Click to expand...


                                        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!


                                        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.

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


                                                        console.log($gameTroop._enemies._hp)


                                                        }                
Click to expand...


 


                                        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.


本贴来自国际rpgmaker官方论坛作者:Internetomancer处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/console-log-is-the-best-script.57848/
页: [1]
查看完整版本: console.log() is the best script!