Skip to content

Commit

Permalink
Merge pull request #2694 from Capostrophic/show
Browse files Browse the repository at this point in the history
Make Show fallback to global variables when sensible (bug #5278)
  • Loading branch information
elsid committed Feb 9, 2020
2 parents 3ce3f36 + 9b4be67 commit 158f610
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
Bug #5255: "GetTarget, player" doesn't return 1 during NPC hello
Bug #5261: Creatures can sometimes become stuck playing idles and never wander again
Bug #5269: Editor: Cell lighting in resaved cleaned content files is corrupted
Bug #5278: Console command Show doesn't fall back to global variable after local var not found
Feature #1774: Handle AvoidNode
Feature #2229: Improve pathfinding AI
Feature #3025: Analogue gamepad movement controls
Expand Down
26 changes: 11 additions & 15 deletions apps/openmw/mwscript/miscextensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,48 +923,44 @@ namespace MWScript
if (!ptr.isEmpty())
{
const std::string& script = ptr.getClass().getScript(ptr);
if (script.empty())
{
output << ptr.getCellRef().getRefId() << " has no script " << std::endl;
}
else
if (!script.empty())
{
const Compiler::Locals& locals =
MWBase::Environment::get().getScriptManager()->getLocals(script);
char type = locals.getType(var);
std::string refId = ptr.getCellRef().getRefId();
if (refId.find(' ') != std::string::npos)
refId = '"' + refId + '"';
switch (type)
{
case 'l':
case 's':
output << ptr.getCellRef().getRefId() << "." << var << ": " << ptr.getRefData().getLocals().getIntVar(script, var);
output << refId << "." << var << " = " << ptr.getRefData().getLocals().getIntVar(script, var);
break;
case 'f':
output << ptr.getCellRef().getRefId() << "." << var << ": " << ptr.getRefData().getLocals().getFloatVar(script, var);
break;
default:
output << "unknown local '" << var << "' for '" << ptr.getCellRef().getRefId() << "'";
output << refId << "." << var << " = " << ptr.getRefData().getLocals().getFloatVar(script, var);
break;
}
}
}
else
if (output.rdbuf()->in_avail() == 0)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
char type = world->getGlobalVariableType (var);

switch (type)
{
case 's':
output << runtime.getContext().getGlobalShort (var);
output << var << " = " << runtime.getContext().getGlobalShort (var);
break;
case 'l':
output << runtime.getContext().getGlobalLong (var);
output << var << " = " << runtime.getContext().getGlobalLong (var);
break;
case 'f':
output << runtime.getContext().getGlobalFloat (var);
output << var << " = " << runtime.getContext().getGlobalFloat (var);
break;
default:
output << "unknown global variable";
output << "unknown variable";
}
}
runtime.getContext().report(output.str());
Expand Down

0 comments on commit 158f610

Please sign in to comment.