Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

AngelScript: added console + cvars #2788

Merged
merged 4 commits into from
Sep 7, 2021
Merged

Conversation

ohlidalp
Copy link
Member

@ohlidalp ohlidalp commented Sep 1, 2021

There are new elements in the scripting interface which allow you to add/modify/read console variables (RoR.cfg settings):

  • global object console
  • class ConsoleClass
  • class CVarClass and enum CVarFlags

Example terrain:
workshop-v2-console.zip
obrazek

Example code:

CVarClass@ cvar_gfx_fov_external = null;
CVarClass@ cvar_gfx_fov_internal = null;
CVarClass@ cvar_test_workshop = null;

// Game entry point - called once when terrain is loaded.
// CAUTION! Runs each time the terrain is reloaded - some things like CVars persist between runs!
void main()
{
    // --- CVar interface test ---
    // Create the CVar. String type is default - no flags.
    // CAUTION - will return the cvar on first map load but null on reload because the cvar already exists!
    console.cVarCreate("test_workshop", "Test - Workshop", /*flags*/ 0, "AngelScript has Console!");
    // Fetch cvars
    @cvar_test_workshop = console.cVarFind("test_workshop");
    @cvar_gfx_fov_external = console.cVarFind("gfx_fov_external");
    @cvar_gfx_fov_internal = console.cVarFind("gfx_fov_internal");
}

// Game entry point - called every frame. Argument is delta time in seconds.
void frameStep(float dt)
{
    ImGui::Text("Test: " + cvar_test_workshop.getStr());
    ImGui::Text("FOV exterior: " + cvar_gfx_fov_external.getStr());
    ImGui::Text("FOV interior: " + cvar_gfx_fov_internal.getStr());
}

@ohlidalp ohlidalp marked this pull request as ready for review September 1, 2021 08:09
@ohlidalp ohlidalp mentioned this pull request Sep 2, 2021
@ohlidalp ohlidalp merged commit d8e3ef3 into RigsOfRods:master Sep 7, 2021
@ohlidalp ohlidalp deleted the as-console branch September 7, 2021 10:57
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants