So i have a question. I have some places with differents maps with a different widgets. And now i wanna merge all widgets to one (if it possible).
For example, I set variable $loc_home and set map inside and set $loc_street. Its two differents maps. Next, i wanna making one widget, who will take arg and set it as a variable. For the arg i wanna use passage() for taking passage name and use it in condition for forming map on page. The name of map variables and passages names are equivalent
If I understand correctly you have two âlocationâ related Passages named loc_home and loc_street, and the meta data associated with those two Passages are contain within the $loc_home and $loc_street Story Variables respectively.
You will need to use the State.variables collection object to gain access to the data contain within the $loc_home and $loc_street Story Variables, using the passed in Passage Name argument to indicate which âStory Variableâ you want the data of.
<<set _loc = State.variables[$args[0]]>>
The following code shows a possible implementation of a âmapâ widget containing your second code example.
warning: The above code has NOT been tested, as I was unsure of the exact contents of the Story Variables you referenced in your examples. It also doesnât check to make sure that the Passage Name being passed into the âmapâ widget has an associated Story Variable.
You can do that, however you canât use $args[0] directly that way. If you add this to the start of your widget:
<<set _tempMap = State.getVar("$" + $args[0])>>
and then use the array in _tempMap (i.e. swap $loc_home for _tempMap in your first example), it should work fine. (See State.getVar() for details.)
Also, instead of using the story variables $i and $k for your loop variables, you should use the temporary variables _i and _k, because you should only use story variables when absolutely necessary to keep data across passage transitions. This is because story variables increase the size of the game history which has to be kept track of, which in turn slows down passage transitions, saves, and loads.
One other thing Iâd suggest is that, instead of doing <<elseif _tempMap[_i][_k] eq #>> for each number, you could shorten that like this:
Thanks for answering. I just couldnât find way to use a binding argument with a variable, but I tried something similar with state.variable. In any case, it partially helped. But!
I try two ways as you say, using first <<set _loc = State.variables[$args[0]]>> and then <<set _tempMap = State.getVar("$" + $args[0])>> but in both ways i have an error Error: <<map>>: error within widget contents (Error: <<for>>: bad conditional expression: Cannot read property 'length' of undefined).
I try <<print passage()>> and it works correctly, showing the name of current passage, so i try both way with widget <<map passage()>> and <<map 'passage()'>>
Just to clarify first, but in case you werenât aware, this part of your code is redundant. You should use one or the other. (I assume youâre aware, Iâm just covering my bases.)
This tells me that the name of the variable (not including the â$â) and the name of the passage arenât the same.
If the name of the variable is â$loc_homeâ, then the name of the passage has to be âloc_homeâ for the above code to work with:
<<map `passage()`>>
(Note that the characters around passage() are not apostrophes, theyâre backquotes, found on the ~ key in the upper-left corner of most keyboards. You have this correct in your first post, but I thought it was worth mentioning for others.)
If the name of the passage is actually â$loc_homeâ, then you could just change my code to:
<<set _loc = State.getVar($args[0])>>
(Youâd need to strip out the â$â, either from the passage names or from the $args[0] value, to get Greyelfâs code to work with passage names like that.)
god what a dumb, i forgot to edit variable $loc_home. It was with old name. Now that works perfectly with your and Greyelf examples! Thank you guys so much I need learn more about hows args works