setActionText(
cmd:getCurrentLanguageName()
.." "..
getScene(walkto):getCurrentLanguageName()
)
-- * function which updates the action text of an object for the current language * --
function setText(obj, txt)
local texts = obj.TextTextLanguages -- get all texts belonging to the object
-- + --
for i = 1, #texts do -- iterate through the stored texts
if texts[i].language == game.StandardLanguage:getId().id then
texts[i].text = txt; obj.TextTextLanguages = texts -- update old text with new text
break -- no need to keep iterating, cancel the loop
end
end
end
setText(game.CurrentScene.SceneObjects["example"].ObjectName, "some new text")
function getObjLangName(obj)
if obj:isEmpty() then
return nil
end
local name
if obj:getId().tableId == eObjects then
name = obj:getLink(VObjectName)
elseif obj:getId().tableId == eCharacters then
name = obj:getLink(VCharacterName)
end
if name:isEmpty() then
return obj:getName()
end
local names = name.TextTextLanguages
for _,v in ipairs(names) do
if v.language == game.StandardLanguage:getId().id then
return v.text
end
end
end
ObjName(game.UsedItem)
function ObjName(obj)
local table = obj:getId().tableId
if table == eObjects then
return obj:getTextStr(VObjectName)
elseif table == eCharacters then
return obj:getTextStr(VCharacterName)
elseif table == eButtons then
return obj:getTextStr(VButtonName)
end
end
Scenes["example"]:getTextStr(VSceneName)
Scenes["example"]:getTextStr( VSceneName, Languages["English"]):getId().id )
Ah yeah, sorry. I used an online translator to translate your text. I guess something got lost in the translation.no, you were right, AFRLme. He wanted to set a language depending text. But his last post was regarding getting it.Scenes["example"]:getTextStr(VSceneName)
Will return the name of the scene based on the currently active language. You can also return the name of a specified language too, but it requires the id rather than the language name. Like so...Scenes["example"]:getTextStr( VSceneName, Languages["English"]):getId().id )
ObjName(game.UsedItem)
function ObjName(obj) local table = obj:getId().tableId if table == eObjects then return obj:getTextStr(VObjectName) elseif table == eCharacters then return obj:getTextStr(VCharacterName) elseif table == eButtons then return obj:getTextStr(VButtonName) end end
mostly historical reasons and the slow process of transition to the new naming system they introduced in V5.ObjName(game.UsedItem)
function ObjName(obj) local table = obj:getId().tableId if table == eObjects then return obj:getTextStr(VObjectName) elseif table == eCharacters then return obj:getTextStr(VCharacterName) elseif table == eButtons then return obj:getTextStr(VButtonName) end end
Ok, makes it a little bit easier. Now tell me:
Why do I have to call the same function on different objects with different arbitrary constants to get the same result (current language ingame name)?
Why not have getGuiName() that every object understands?
At least, shouldnt it be the job of the object to know where to find its name?
Now I just need to know:There is a whole hook function which gets triggered when the action text changes it returns the new actiontext..
how do I change the action text?
if (_qp == nil) then
_qp = {}
math.randomseed( os.time() )
end
_qp.cmd = {}
_qp.cmd.objThis = emptyObject
_qp.cmd.objLast = emptyObject
_qp.cmd.cmdLast = emptyObject
_qp.cmd.altAction = nil
_qp.cmd['cmdWalk'] = getObject('Interfaces[_default].InterfaceButtons[cmdWalk]')
_qp.cmd['cmdLook'] = getObject('Interfaces[_default].InterfaceButtons[cmdLook]')
_qp.cmd['cmdUse'] = getObject('Interfaces[_default].InterfaceButtons[cmdUse]')
_qp.cmd['cmdTalk'] = getObject('Interfaces[_default].InterfaceButtons[cmdTalk]')
_qp.cmd['cmdGive'] = getObject('Interfaces[_default].InterfaceButtons[cmdGive]')
_qp.cmd['cmdTake'] = getObject('Interfaces[_default].InterfaceButtons[cmdTake]')
_qp.cmd['cmdPush'] = getObject('Interfaces[_default].InterfaceButtons[cmdPush]')
_qp.cmd['cmdPull'] = getObject('Interfaces[_default].InterfaceButtons[cmdPull]')
_qp.cmd['cmdOpen'] = getObject('Interfaces[_default].InterfaceButtons[cmdOpen]')
_qp.cmd['cmdClose'] = getObject('Interfaces[_default].InterfaceButtons[cmdClose]')
registerEventHandler('mainLoop', '_qpmain')
_qp.getObjLangName = function(obj)
if obj:isEmpty() then
return "--: empty :--"
end
local id = obj:getId().tableId
if id == eObjects then
return obj:getTextStr(VObjectName)
elseif id == eCharacters then
return obj:getTextStr(VCharacterName)
elseif id == eScenes then
return obj:getTextStr(VSceneName)
elseif id == eButtons then
return obj:getTextStr(VButtonName)
end
end
_qp.cmd.setActionText = function(text)
print(text)
end
_qp.cmd.callItemCommand = function(_cmd, _item)
-- NYI
return false
end
function _qpmain()
_qp.cmd.objThis = game:getLink(VGameCurrentObject)
-- skip if nothing happend
if _qp.cmd.objThis == _qp.cmd.lastObj
then return end
_qp.cmd.altAction = nil
_qp.cmd.onChangeObjectcommand()
_qp.cmd.lastObj = _qp.cmd.objThis
end
_qp.cmd.onChangeObjectcommand = function()
if _qp.cmd.objThis:isEmpty() or
_qp.cmd.objThis:getId().tableId ~= eObjects then
return false
end
-- get command object and internal command name
local cmd = game:getLink(VGameActiveCommand)
local cmdName = cmd:getName()
for _,v in ipairs(_qp.cmd.objThis:getLinks(VObjectValues)) do
local valName = v:getName()
local valStr = v:getStr(VValueString)
-- check if cmd is overridden by object
if valName == cmdName then
if _qp.cmd[valStr] ~= nil then
game:setValue(VGameActiveCommand, _qp.cmd[valStr])
end
return true
end
-- check for cmdWalk with walkto
if cmdName == "cmdWalk" and valName == "walkto" then
-- change action text
_qp.cmd.altAction = _qp.getObjLangName(cmd)..
" ".._qp.getObjLangName(Scenes[valStr])
return true
end
-- check if object represents an item
if valName == "item" then
-- call items command action
return _qp.cmd.callItemCommand(cmd, Items[valStr])
end
end
return false
end