How to $args

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 )’

how i can fix that? thanks in advance

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:

<<hovertip $args[1].desc>><<= $args[1].namel>><</hovertip>>

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:

<<transfer '$starthomefloor' '$player.args[0]' '$args[1]'>>

should probably be done like this instead:

<<transfer '$starthomefloor' `'$player.' + $args[0]` $args[1]>>

The backquotes around '$player.' + $args[0] will also turn that part into a single value, like “$player.pants”.

Hope that helps! :slight_smile:

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.

EDIT: Fixed missing $'s.

Thanks for your answer, but i think it still not working for me. I make your correction to code, but my string still looks like

$args[1].namel ( wear | you have no backpack )

this hows my code looks like now

<<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]>>
			<</link>>
		<<else>>
			you have no backpack
		<</if>>)
<</widget>>

and in addition to that, the browser started throwing an error

image

this part of the code may be useful. I use regular variables to set items in the game. Example

<<set $homepants to {
	nameu: 'Home pants',
	namel: 'home pants',
	desc: 'just your home pants...'
}>>

and inventory

<<newinventory '$player.pants'>>

Sorry, a couple of missing $'s there that I didn’t notice. The first one was here:

<<transfer '$starthomefloor' `'$player.' + $args[0]` $args[1]>>

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.