JS.setCommands ("") adding to List of commands
fuchs
22 Apr 2022, 22:30I use JS.setCommands ("") to add commands the player can click on the toolbar.
The Problem is calling JS.setCommands ("") overrides the command previously stored there. Is there a way to append to the list of commands? instead of overwriting?
mrangel
22 Apr 2022, 23:41Just include the ones that are already there in your list. If it's a dynamic list that you want to add and remove elements of at different times, it would make sense to make a Quest attribute containing the list.
You could give the game a stringlist attribute containing the commands. Whenever you want to add one, you would add it to that list; something like:
list add (game.commandpanecommands, "jump")
JS.setCommands(Join (ListCompact (game.commandpanecommands), ";"))
Or you could put something in your UI initialisation script to create a new JS.addCommands
function:
JS.eval("$(function(){window.addCommands=function(a,b){for(2==arguments.length&&(commandColour=b),ary=a.split(\";\"),el=$(\"#commandPaneHeading\"),i=0;i<ary.length;i++)ary2=ary[i].split(\":\"),comm=ary2[0],commLower=ary2[0].toLowerCase().replace(/ /g,\"_\"),commComm=(2==ary2.length?ary2[1]:ary2[0]).toLowerCase(),el.append(\" <span id=\\\"\"+commLower+\"_command_button\\\" class=\\\"accordion-header-text\\\" style=\\\"padding:5px;\\\"><a id=\\\"verblink\"+commLower+\"\\\" class=\\\"cmdlink commandlink\\\" style=\\\"text-decoration:none;color:\"+commandColour+\";font-size:12pt;\\\" data-elementid=\\\"\\\" data-command=\\\"\"+commComm+\"\\\">\"+comm+\"</a></span> \")}});")