Hello. I have some questions. Im new here and little unexperienced but my wish to create is strong hehe
So, question. I make a widget, while im setting two args. First is set body part were item will placed. Next args is name of item what we taking or wear. Example
<<widget 'pickuping1'>>
<<hovertip '$args[1].desc'>>$args[1].namel<</hovertip>>
( <<link 'wear' `passage()`>>
<<transfer '$starthomefloor' '$player.args[0]' '$args[1]'>>
you have new item
<</link>>
|
<<if $player.backpack.has('homebackpack')>>
<<link 'place in backpack' `passage()`>>
<<transfer '$starthomefloor' '$backpack' '$args[1]'>>
<<nadi>>
<</link>>
<<else>>
you have no backpack
<</if>>)
<</widget>>
and how i execute it
<<pickuping 'pants' 'homepants'>>
but i have this â$args[1].namel ( wear | you have no backpack )â
SugarCube has limitations on what kinds of ânaked variablesâ it will display as values. In this case, the problem is that it wonât show values in property names after a â[1]â like that.
Instead, youâll need to use the <<print>> macro to display that (or the shorter alias for that macro, <<=>>). Thus, your code should be something like this:
That should now display the value of that variable, rather than displaying it as text.
Also, note that you should NOT have the quotes around $args[1].desc in the <<hovertip>> macro, since needs the value of that variable, not the name of the variable. Looking at the <<transfer>> macro documentation, the third parameter in that is the same, in that it should receive a value, rather than the name of a variable. So, this line:
The backquotes around '$player.' + $args[0] will also turn that part into a single value, like â$player.pantsâ.
Hope that helps!
P.S. I also note that you have <<widget 'pickuping1'>>, and then call <<pickuping 'pants' $homepants>>. I assume that the â1â in âpickuping1â is a typo, since it shouldnât be there if thatâs how youâre calling the widget.
I originally forgot the $ thatâs supposed to be in front of $args[0].
The other issue is that you keep putting variable names inside quotes, when they shouldnât be. If the widget is called âpickuping1â then you should be calling it like this:
<<pickuping1 'pants' $homepants>>
With the $ in front of $homepants, and no quotes around it. This way, instead of passing a string with the word âhomepantsâ in it, you pass a reference to the $homepants object variable, and thus the code can access its properties from the $args[1] variable. (The quotes around âpantsâ is fine, because youâre just passing a string there, not a variable.)
The vast majority of time you should NOT to put quotes around your variables when you have them as parameters in a macro or function call. Only when the documentation explicitly says that it has to be âthe name of the variableâ in a parameter, should you put the variable name within single- or double-quotes.
Iâve fixed my earlier post to reflect the above corrections.
yeah, now string looks how it should be thanks^^ but error with args0 isnt inventory still exists while i send item to backpack. I try it with different inv variables, not only pants, and its doesnt works
Are the variables that youâre using inventories created by using <<newinventory>> or the Inventory() constructor? If they arenât valid variables, then it wonât work.
If that doesnât solve it, youâll need to show enough code so that we can figure out whatâs going wrong, because otherwise it could be a bunch of different things.
I apologize for such a long answer. There was no way to answer. I try as args[0] to specify the inventory to which I will transfer the thing. This inventory is specified via <<newinventory>>.
right now i use macros where i use to point each items what try to add. Looks like
<<widget 'pickuping'>>
<<set $pickuping to $args[0]>>
<<if $pickuping is 'homepants'>>
<<hovertip '$homepants.desc'>>$homepants.namel<</hovertip>>
( <<link 'ĐĐ°ĐŽĐ”ŃŃ' `passage()`>>
<<transfer '$starthomefloor' '$player.pants' 'homepants'>>
weared
<</link>>
|
<<if $player.backpack.has('homebackpack')>>
<<link 'ĐĐŸĐ»ĐŸĐ¶ĐžŃŃ ĐČ ŃŃĐșĐ·Đ°Đș' `passage()`>>
<<transfer '$starthomefloor' '$backpack' 'homepants'>>
new item in backpack
<</link>>
<<else>>
you have no backpack
<</if>>)
<</widget>>
using: <<pickuping 'homepants'>> where i use only item and macros transfer it to specified inventory
But to point each item in code makes construction is long and hard. And now im trying make widget ehere i can use args to set inventory (args[0]) and item (args[1]). After your recommendations i make this monster
<<widget 'pickuping1'>>
<<hovertip '$args[1].desc'>>$args[1].namel<</hovertip>>
( <<link 'wear' `passage()`>>
<<transfer '$starthomefloor' `'$player.' + $args[0]` $args[1]>>
weared
<</link>>
|
<<if $player.backpack.has('homebackpack')>>
<<link 'place in backpack' `passage()`>>
<<transfer '$starthomefloor' '$backpack' '$args[1]'>>
new item in backpack
<</link>>
<<else>>
you have no backpack
<</if>>)
<</widget>>
using: <<pickuping 'pants' 'homepants '>> where pants is an inventory (args[0]) and homepants is item (args[1])