Jump to content

How do you use the 0AD console?


howlingflute
 Share

Recommended Posts

I really like 0AD so far. I wanted to try messing around with some of the options in game with the console but must be doing something wrong since I only get syntax errors. I followed the instructions found at http://trac.wildfire...wiki/Playing0AD on how to use the console. I even tried writing some of those commands verbatim only to get a syntax error message in the console.

For example I tried

:players[1].resources.food += 1000

and got

ERROR: JavaScript error: Console line 1

SyntaxError: syntax error

I would appreciate it if someone lets me know what I am doing wrong or point me to the right place to look.

What I really wanted to do was something like this

:getEntityTemplate("template_structure_civic_civil_centre", -1).TerritoryInfluence.Radius = 400

but since the simpler thing didn't work I am figuring I am just doing something wrong. Do I perhaps need to build the game in debug mode?

Currently I am compiling from svn source with the release option. Thanks for your help.

Link to comment
Share on other sites

Hmm, the console information on that page is almost entirely wrong - someone should probably fix it (or just delete it).

Currently the console is running in the GUI script context. That means you can't access the simulation state directly - you can only interact with it using the same function calls that GUI scripts can use, which don't allow you to do things like change a player's resources. (Also you don't prefix with ":" or "?" any more, just type in the JS statement directly.)

If you want to change the parameters set in the entity template XML files (binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml), you'll have to just edit those XML files then restart the game - there's no way to change them at runtime.

Link to comment
Share on other sites

Thanks for the response. Its too bad that you can't edit the state of the game directly at the moment. Would have been nice to be able to give myself resources :P. Since there is nothing about console commands on the wiki that is correct I searched the code and found a few commands that work in the console.

There were two locations for script bindings (that I could find) ScriptGlue.cpp and ScriptFunctions.cpp. I copied the relevant parts of each file below

Let me know if there are any other locations that I missed. Thanks.

The following were found in ScriptGlue.cpp and work directly in the console without a prefix. I would recommned not using endGame() as it will end your game but also with a core dump. Also note some of these commands require you to be running a debug version of the game.

	// Profiling
JS_FUNC("startXTimer", StartJsTimer, 1)
JS_FUNC("stopXTimer", StopJsTimer, 1)

// Game Setup
JS_FUNC("endGame", EndGame, 0)

// VFS (external)
JS_FUNC("buildDirEntList", JSI_VFS::BuildDirEntList, 1)
JS_FUNC("getFileMTime", JSI_VFS::GetFileMTime, 1)
JS_FUNC("getFileSize", JSI_VFS::GetFileSize, 1)
JS_FUNC("readFile", JSI_VFS::ReadFile, 1)
JS_FUNC("readFileLines", JSI_VFS::ReadFileLines, 1)
JS_FUNC("archiveBuilderCancel", JSI_VFS::ArchiveBuilderCancel, 1)

// Misc. Engine Interface
JS_FUNC("exit", ExitProgram, 0)
JS_FUNC("isPaused", IsPaused, 0)
JS_FUNC("setPaused", SetPaused, 1)
JS_FUNC("setCursor", SetCursor, 1)
JS_FUNC("getFPS", GetFps, 0)
JS_FUNC("getGUIObjectByName", GetGUIObjectByName, 1)

// Miscellany
JS_FUNC("buildTime", GetBuildTimestamp, 0)
JS_FUNC("dumpHeaps", DumpHeaps, 0)



{ "console" , GLOBAL_CONSOLE, JSPROP_PERMANENT|JSPROP_READONLY, JSI_Console::getConsole, 0 },
{ "gameView" , 0, JSPROP_PERMANENT|JSPROP_READONLY, GetGameView, 0 },
{ "renderer" , 0, JSPROP_PERMANENT|JSPROP_READONLY, GetRenderer, 0 },

The following commands work with Engine prefix and were found in ScriptFunctions.cpp. For example to change the simulation rate of the game you would use the command

Engine.SetSimRate(2)

	// GUI manager functions:
scriptInterface.RegisterFunction<CScriptVal, &GetActiveGui>("GetActiveGui");
scriptInterface.RegisterFunction<void, std::wstring, CScriptVal, &PushGuiPage>("PushGuiPage");
scriptInterface.RegisterFunction<void, std::wstring, CScriptVal, &SwitchGuiPage>("SwitchGuiPage");
scriptInterface.RegisterFunction<void, &PopGuiPage>("PopGuiPage");

// Simulation<->GUI interface functions:
scriptInterface.RegisterFunction<CScriptVal, std::wstring, CScriptVal, &GuiInterfaceCall>("GuiInterfaceCall");
scriptInterface.RegisterFunction<void, CScriptVal, &PostNetworkCommand>("PostNetworkCommand");

// Entity picking
scriptInterface.RegisterFunction<std::vector<entity_id_t>, int, int, &PickEntitiesAtPoint>("PickEntitiesAtPoint");
scriptInterface.RegisterFunction<std::vector<entity_id_t>, int, int, int, int, int, &PickFriendlyEntitiesInRect>("PickFriendlyEntitiesInRect");
scriptInterface.RegisterFunction<std::vector<entity_id_t>, std::string, bool, bool, &PickSimilarFriendlyEntities>("PickSimilarFriendlyEntities");
scriptInterface.RegisterFunction<CFixedVector3D, int, int, &GetTerrainAtPoint>("GetTerrainAtPoint");

// Network / game setup functions
scriptInterface.RegisterFunction<void, &StartNetworkGame>("StartNetworkGame");
scriptInterface.RegisterFunction<void, CScriptVal, int, &StartGame>("StartGame");
scriptInterface.RegisterFunction<void, std::wstring, &StartNetworkHost>("StartNetworkHost");
scriptInterface.RegisterFunction<void, std::wstring, std::string, &StartNetworkJoin>("StartNetworkJoin");
scriptInterface.RegisterFunction<void, &DisconnectNetworkGame>("DisconnectNetworkGame");
scriptInterface.RegisterFunction<CScriptVal, &PollNetworkClient>("PollNetworkClient");
scriptInterface.RegisterFunction<void, CScriptVal, &SetNetworkGameAttributes>("SetNetworkGameAttributes");
scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer");
scriptInterface.RegisterFunction<void, std::wstring, &SendNetworkChat>("SendNetworkChat");
scriptInterface.RegisterFunction<std::vector<CScriptValRooted>, &GetAIs>("GetAIs");

// Misc functions
scriptInterface.RegisterFunction<std::wstring, std::wstring, &SetCursor>("SetCursor");
scriptInterface.RegisterFunction<int, &GetPlayerID>("GetPlayerID");
scriptInterface.RegisterFunction<std::wstring, &GetDefaultPlayerName>("GetDefaultPlayerName");
scriptInterface.RegisterFunction<void, std::string, &OpenURL>("OpenURL");
scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas");
scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable");
scriptInterface.RegisterFunction<CScriptVal, VfsPath, &LoadMapSettings>("LoadMapSettings");
scriptInterface.RegisterFunction<CScriptVal, &GetMapSettings>("GetMapSettings");
scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollow>("CameraFollow");
scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollowFPS>("CameraFollowFPS");
scriptInterface.RegisterFunction<entity_id_t, &GetFollowedEntity>("GetFollowedEntity");
scriptInterface.RegisterFunction<bool, std::string, &HotkeyIsPressed_>("HotkeyIsPressed");
scriptInterface.RegisterFunction<void, std::wstring, &DisplayErrorDialog>("DisplayErrorDialog");
scriptInterface.RegisterFunction<CScriptVal, &GetProfilerState>("GetProfilerState");

// User report functions
scriptInterface.RegisterFunction<bool, &IsUserReportEnabled>("IsUserReportEnabled");
scriptInterface.RegisterFunction<void, bool, &SetUserReportEnabled>("SetUserReportEnabled");
scriptInterface.RegisterFunction<std::string, &GetUserReportStatus>("GetUserReportStatus");
scriptInterface.RegisterFunction<void, std::string, int, std::wstring, &SubmitUserReport>("SubmitUserReport");

// Development/debugging functions
scriptInterface.RegisterFunction<void, float, &SetSimRate>("SetSimRate");
scriptInterface.RegisterFunction<void, int, &SetTurnLength>("SetTurnLength");
scriptInterface.RegisterFunction<void, float, float, float, &SetCameraTarget>("SetCameraTarget");
scriptInterface.RegisterFunction<int, &Crash>("Crash");
scriptInterface.RegisterFunction<void, &DebugWarn>("DebugWarn");
scriptInterface.RegisterFunction<void, &ForceGC>("ForceGC");
scriptInterface.RegisterFunction<void, &DumpSimState>("DumpSimState");
scriptInterface.RegisterFunction<void, unsigned int, &EnableTimeWarpRecording>("EnableTimeWarpRecording");
scriptInterface.RegisterFunction<void, &RewindTimeWarp>("RewindTimeWarp");

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...