0 votes
by (180 points)
closed by
<<for $sale = 0; $sale < $storepet.length; $sale++>>\
<<set $pet = $storepet[$sale]>>
<<print $pet.name>>
<<print $pet.Description>>
<<print $pet.Price>>
<<if $pcgold >= $pet.Price>>Do you wish to <<link Purchase? Purchased>><<set $pcpet.pushUnique($girl)>><<set $storepet.delete($pet)>><<set $pcgold -= $pet.Price>><</link>>
<<else>>
You do not have enough to purchase it
<</if>>
<</for>>
closed with the note: I have found the answer to my own problem

1 Answer

0 votes
by (23.6k points)
edited by

With a for loop like this you'll need to use the <<capture>> macro when setting up a link. Also you forgot the quotation marks within your <<link>>. I'm guessing something like this should work the way you want (didn't have time to test it though):

<<nobr>>
<<for _sale to 0; _sale lt $storepet.length; _sale++>>
    <<set $pet to $storepet[_sale].name>>
    <br>
    $pet.Description
    <br>
    $pet.Price
    <br>
    <<if $pcgold >= $pet.Price>>
        <<capture $pet>>
        <<linkreplace "Do you wish to purchase?">>
            Purchased
            <<set $pcpet.pushUnique($girl)>>
            <<set $storepet.delete($pet)>>
            <<set $pcgold -= $pet.Price>>
        <</linkreplace>>
        <</capture>>
    <<else>>
        You do not have enough to purchase it
    <</if>>
<</for>>
<</nobr>>

 

by (44.7k points)

Idling's answer should help.  That said, the <<capture>> macro can be a bit tricky to understand at first.  If you need it further explained, I have some <<capture>> sample code here which helps explain it a bit more.  (Click the "Jump to Start" link in the UI bar for other sample code.)

Enjoy!

by (180 points)
edited by
this did not help im still getting the error of uniquepush undefined even thouhg i had to edit  cause the source variable ended (by accident i guess) as [_sale].name and not _sale so even when i edited it i still come up with my original problem

<<nobr>>
<<for _sale to 0; _sale lt $storepet.length; _sale++>>
    <<set $pet to $storepet[_sale]>>
    <br>
    $pet.name
    <br>
    $pet.Description
    <br>
    $pet.Price
    <br>
    <<if $pcgold >= $pet.Price>>
        <<capture $pet>>
        <<linkreplace "Do you wish to purchase?">>
            Purchased
            <<set $pcpet.pushUnique($pet)>>
            <<set $storepet.delete($pet)>>
            <<set $pcgold -= $pet.Price>>
        <</linkreplace>>
        <</capture>>
    <<else>>
        You do not have enough to purchase it
    <</if>>
<</for>>
<</nobr>>
by (63.1k points)

im still getting the error of uniquepush undefined

You never actually mentioned the error. What version of SugarCube 2 are you using?

by (180 points)
edited by
im using 2.21.0

though i guess i was VERY ambigous with halp plz not working
by (23.6k points)

In your original example you say:

<<set $pcpet.pushUnique($girl)>>

Which has now suddenly changed to

<<set $pcgirl.pushUnique($pet)>>

Which is it?

by (180 points)
its pet like woops for both my b
by (23.6k points)
It's what for both your what?
by (180 points)
its <<set $pcpet.pushUnique ($pet)>>
...