MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / getVariable

Function getVariable

TheForceEngine/TFE_FrontEndUI/console.cpp:748–795  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

746 }
747
748 void getVariable(const char* name, char* value)
749 {
750 CVar* var = nullptr;
751 size_t count = s_var.size();
752 for (size_t i = 0; i < count; i++)
753 {
754 if (s_var[i].name == name)
755 {
756 var = &s_var[i];
757 break;
758 }
759 }
760 if (!var)
761 {
762 char errorMsg[CSTR_LEN];
763 sprintf(errorMsg, "get - Unknown variable \"%s\"", name);
764 s_history.push_back({ c_historyErrorColor, errorMsg });
765 return;
766 }
767 if (!var->valuePtr)
768 {
769 char errorMsg[CSTR_LEN];
770 sprintf(errorMsg, "get - Variable not initialized \"%s\"", name);
771 s_history.push_back({ c_historyErrorColor, errorMsg });
772 return;
773 }
774
775 char msg[CSTR_LEN];
776 msg[0] = 0;
777
778 switch (var->type)
779 {
780 case CVAR_INT:
781 sprintf(msg, "%s = %d", var->name.c_str(), *var->valueInt);
782 break;
783 case CVAR_FLOAT:
784 sprintf(msg, "%s = %f", var->name.c_str(), *var->valueFloat);
785 break;
786 case CVAR_BOOL:
787 sprintf(msg, "%s = %s", var->name.c_str(), *var->valueBool ? "true" : "false");
788 break;
789 case CVAR_STRING:
790 sprintf(msg, "%s = \"%s\"", var->name.c_str(), var->valueString);
791 break;
792 };
793
794 s_history.push_back({ c_historyDefaultColor, msg });
795 }
796}

Callers 1

c_getFunction · 0.85

Calls 3

push_backMethod · 0.80
c_strMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected