HTML Twine 2 Sugarcube Pulling information from an array in a for loop overwrites it?

WiseGuyAnimates

Newbie
Game Developer
Oct 25, 2018
22
25
I'm trying to link to different captured creatures in an array using unique ids generated using Date now function, and their names which brings up a video. but it just overwrites the id with the last one pulled from the array in the for loop. all the information displays on TrainingArea properly, but when i go to Viewcreature it overwrites the id with the last creature captured (and subsequently the last loop) so all links lead to the last creature. Any help is appreciated.
HTML:
:: TrainingArea
<<for _creature range $creatures>>
    <<set _creatureID = _creature.id>>
  
    <!-- Link to the single ViewCreature passage and pass the creature ID -->
    <<link _creature.name>>
        <<set $currentCreatureID = _creatureID>>
        <<goto "ViewCreature">>
    <</link>>

    - HP: <<_creature.currentHP>> / <<_creature.maxHP>>
    - Attack Damage: <<_creature.damage>>
    - Relationship: <<_creature.relationship>>

    <!-- Equip option based on relationship level -->
    <<if _creature.equipped>>
        (Equipped for battle)
    <<elseif _creature.relationship >= 100>>
        [[Equip for battle->EquipCreature]]
        <<set $currentCreatureID = _creatureID>>
    <</if>>

    <<silently>>
    <!-- Testing links to set relationship levels (Hidden from the player) -->
    **[Set Relationship:**
    <<link "10">>
        <<set $creatures[$creatures.indexOf(_creature)].relationship = 10>>
        <<goto "TrainingArea">>
    <</link>>
    <<link "30">>
        <<set $creatures[$creatures.indexOf(_creature)].relationship = 30>>
        <<goto "TrainingArea">>
    <</link>>
    <<link "50">>
        <<set $creatures[$creatures.indexOf(_creature)].relationship = 50>>
        <<goto "TrainingArea">>
    <</link>>
    <<link "100">>
        <<set $creatures[$creatures.indexOf(_creature)].relationship = 100>>
        <<goto "TrainingArea">>
    <</link>>
    **]**
    <</silently>>

    <<print "\n">>
<</for>>

[[Back to Hub->HubArea]]
HTML:
:: ViewCreature
<<set _creature = $creatures.find(c => c.id == $currentCreatureID)>>

**<<print _creature.name>>**

<!-- Display relevant information and videos based on creature name -->
<<if _creature.name == "Hinata">>
    <<set _videos = [
        "Videos/Hinata/Viewcreature/Hinataview1.mp4",
        "Videos/Hinata/Viewcreature/Hinataview2.mp4",
        "Videos/Hinata/Viewcreature/Hinataview3.mp4",
        "Videos/Hinata/Viewcreature/Hinataview4.mp4",
        "Videos/Hinata/Viewcreature/Hinataview5.mp4",
        "Videos/Hinata/Viewcreature/Hinataview6.mp4"
    ]>>
    Hinata stands before you, her posture slightly hunched, eyes flicking nervously as she waits for your command. Despite her shyness, there’s a subtle eagerness in her stance, as if she’s hoping to prove herself useful, even if she’s unsure how to do so. Her desire for approval is clear, though she struggles to meet your gaze directly.

<<elseif _creature.name == "Krystal">>
    <<set _videos = [
        "Videos/Krystal/View/Krystalview1.mp4",
        "Videos/Krystal/View/Krystalview2.mp4",
        "Videos/Krystal/View/Krystalview3.mp4",
        "Videos/Krystal/View/Krystalview4.mp4",
        "Videos/Krystal/View/Krystalview5.mp4",
        "Videos/Krystal/View/Krystalview6.mp4",
        "Videos/Krystal/View/Krystalview7.mp4",
        "Videos/Krystal/View/Krystalview8.mp4"
    ]>>
    Krystal stands tall, her posture proud yet subdued. She’s clearly aware of her strength and beauty, but the subtle lowering of her head betrays her recognition of your dominance. Though she doesn’t look directly at you, it’s obvious she’s waiting for your next move, ready to follow your orders with a quiet grace that contrasts with her inner pride.

<<elseif _creature.name == "Raven">>
    <<set _videos = [
        "Videos/Raven/View/Ravenview1.mp4",
        "Videos/Raven/View/Ravenview2.mp4",
        "Videos/Raven/View/Ravenview3.mp4",
        "Videos/Raven/View/Ravenview4.mp4",
        "Videos/Raven/View/Ravenview5.mp4"
    ]>>
    You step into the training room, the air thick with anticipation. Raven is already there, standing at attention, her eyes fixed on you with an intensity that is almost unnerving. Her naked body is tense, every muscle poised for your command. The dim light casts shadows that highlight the curves of her form, making her look like a statue of pure, unadulterated desire.

    She inhales sharply, her breath hitching as she waits for your next move. Her eyes, though silent, convey an unspoken hunger, a craving for whatever you have in mind.
<</if>>

<<set _selectedVideo = _videos.random()>>

<!-- Display the selected video with autoplay and loop -->
<<= '<video src="' + _selectedVideo + '" autoplay loop controls style="width: 100%; max-width: 800px; height: auto;"></video>'>>

- HP: <<print _creature.currentHP>> / <<print _creature.maxHP>>
- Attack Damage: <<print _creature.damage>>
- Relationship: <<print _creature.relationship>>

What would you like to do?

<!-- Links to separate passages -->
[[Watch from across the room->WatchCreature]]

<<if _creature.relationship >= 10>>
    [[Hug->HugCreature]]
<<else>>
    You need a relationship level of 10 or higher to hug <<print _creature.name>>.
<</if>>

<<if _creature.relationship >= 30>>
    [[Feed->FeedCreature]]
<<else>>
    You need a relationship level of 30 or higher to feed <<print _creature.name>>.
<</if>>

<<if _creature.relationship >= 70>>
    [[Missionary Sex ->SleepWithCreature]]
<<else>>
    You need a relationship level of 70 or higher to access this event with <<print _creature.name>>.
<</if>>

<<if _creature.relationship >= 80>>
    [[Anal From behind ->Anal From Behind]]
<<else>>
    You need a relationship level of 80 or higher to access this event with <<print _creature.name>>.
<</if>>

<!-- Equip option based on relationship level -->
<<if _creature.relationship >= 100 and not _creature.equipped>>
    <<link "Equip <<print _creature.name>> for Battle">>
        <!-- Unequip any currently equipped creature -->
        <<for _c range $creatures>>
            <<if _c.equipped>>
                <<set _c.equipped = false>>
                <<set $creatures[$creatures.indexOf(_c)] = _c>>
            <</if>>
        <</for>>
      
        <!-- Equip the selected creature -->
        <<set $creatures[$creatures.indexOf(_creature)].equipped = true>>
        <<goto "ViewCreature">>
    <</link>>
<</if>>
<<if _creature.equipped>>
    <<print _creature.name>> is currently equipped for battle.
<</if>>

[[Back to Training Area->TrainingArea]]
I can grab info out of the array like this below but it only works for a limited number of times (set manually)
HTML:
<<set _creature1 = $creatures[0]>>
<<if _creature1>>
    <<set _creatureID1 = _creature1.id>>

    <!-- Display the first creature's details -->
    <<link _creature1.name>>
        <<set $currentCreatureID = _creatureID1>>
        <<goto "ViewCreature">>
    <</link>>
    (ID: <<print _creatureID1>>)
    - HP: <<_creature1.currentHP>> / <<_creature1.maxHP>>
    - Attack Damage: <<_creature1.damage>>
    - Relationship: <<_creature1.relationship>>

    <!-- Equip option based on relationship level -->
    <<if _creature1.equipped>>
        (Equipped for battle)
    <<elseif _creature1.relationship >= 100>>
        <<link "Equip for battle">>
            <<set $currentCreatureID = _creatureID1>>
            <<goto "EquipCreature">>
        <</link>>
    <</if>>
    <<print "\n">>
<</if>>

<<set _creature2 = $creatures[1]>>
<<if _creature2>>
    <<set _creatureID2 = _creature2.id>>

    <!-- Display the second creature's details -->
    <<link _creature2.name>>
        <<set $currentCreatureID = _creatureID2>>
        <<goto "ViewCreature">>
    <</link>>
    (ID: <<print _creatureID2>>)
    - HP: <<_creature2.currentHP>> / <<_creature2.maxHP>>
    - Attack Damage: <<_creature2.damage>>
    - Relationship: <<_creature2.relationship>>

    <!-- Equip option based on relationship level -->
    <<if _creature2.equipped>>
        (Equipped for battle)
    <<elseif _creature2.relationship >= 100>>
        <<link "Equip for battle">>
            <<set $currentCreatureID = _creatureID2>>
            <<goto "EquipCreature">>
        <</link>>
    <</if>>
    <<print "\n">>
<</if>>

<<set _creature3 = $creatures[2]>>
<<if _creature3>>
    <<set _creatureID3 = _creature3.id>>

    <!-- Display the third creature's details -->
    <<link _creature3.name>>
        <<set $currentCreatureID = _creatureID3>>
        <<goto "ViewCreature">>
    <</link>>
    (ID: <<print _creatureID3>>)
    - HP: <<_creature3.currentHP>> / <<_creature3.maxHP>>
    - Attack Damage: <<_creature3.damage>>
    - Relationship: <<_creature3.relationship>>

    <!-- Equip option based on relationship level -->
    <<if _creature3.equipped>>
        (Equipped for battle)
    <<elseif _creature3.relationship >= 100>>
        <<link "Equip for battle">>
            <<set $currentCreatureID = _creatureID3>>
            <<goto "EquipCreature">>
        <</link>>
    <</if>>
    <<print "\n">>
<</if>>

[[Back to Hub->HubArea]]
 
Last edited:

Alcahest

Engaged Member
Donor
Game Developer
Jul 28, 2017
3,405
4,238
I'm trying to link to different captured creatures in an array using unique ids generated using Date now function, and their names which brings up a video. but it just overwrites the id with the last one pulled from the array in the for loop. all the information displays on TrainingArea properly, but when i go to Viewcreature it overwrites the id with the last creature captured (and subsequently the last loop) so all links lead to the last creature. Any help is appreciated.
HTML:
:: TrainingArea
<<for _creature range $creatures>>
    <<set _creatureID = _creature.id>>

    <!-- Link to the single ViewCreature passage and pass the creature ID -->
    <<link _creature.name>>
        <<set $currentCreatureID = _creatureID>>
        <<goto "ViewCreature">>
    <</link>>

    - HP: <<_creature.currentHP>> / <<_creature.maxHP>>
    - Attack Damage: <<_creature.damage>>
    - Relationship: <<_creature.relationship>>

    <!-- Equip option based on relationship level -->
    <<if _creature.equipped>>
        (Equipped for battle)
    <<elseif _creature.relationship >= 100>>
        [[Equip for battle->EquipCreature]]
        <<set $currentCreatureID = _creatureID>>
    <</if>>

    <<silently>>
    <!-- Testing links to set relationship levels (Hidden from the player) -->
    **[Set Relationship:**
    <<link "10">>
        <<set $creatures[$creatures.indexOf(_creature)].relationship = 10>>
        <<goto "TrainingArea">>
    <</link>>
    <<link "30">>
        <<set $creatures[$creatures.indexOf(_creature)].relationship = 30>>
        <<goto "TrainingArea">>
    <</link>>
    <<link "50">>
        <<set $creatures[$creatures.indexOf(_creature)].relationship = 50>>
        <<goto "TrainingArea">>
    <</link>>
    <<link "100">>
        <<set $creatures[$creatures.indexOf(_creature)].relationship = 100>>
        <<goto "TrainingArea">>
    <</link>>
    **]**
    <</silently>>

    <<print "\n">>
<</for>>

[[Back to Hub->HubArea]]
HTML:
:: ViewCreature
<<set _creature = $creatures.find(c => c.id == $currentCreatureID)>>

**<<print _creature.name>>**

<!-- Display relevant information and videos based on creature name -->
<<if _creature.name == "Hinata">>
    <<set _videos = [
        "Videos/Hinata/Viewcreature/Hinataview1.mp4",
        "Videos/Hinata/Viewcreature/Hinataview2.mp4",
        "Videos/Hinata/Viewcreature/Hinataview3.mp4",
        "Videos/Hinata/Viewcreature/Hinataview4.mp4",
        "Videos/Hinata/Viewcreature/Hinataview5.mp4",
        "Videos/Hinata/Viewcreature/Hinataview6.mp4"
    ]>>
    Hinata stands before you, her posture slightly hunched, eyes flicking nervously as she waits for your command. Despite her shyness, there’s a subtle eagerness in her stance, as if she’s hoping to prove herself useful, even if she’s unsure how to do so. Her desire for approval is clear, though she struggles to meet your gaze directly.

<<elseif _creature.name == "Krystal">>
    <<set _videos = [
        "Videos/Krystal/View/Krystalview1.mp4",
        "Videos/Krystal/View/Krystalview2.mp4",
        "Videos/Krystal/View/Krystalview3.mp4",
        "Videos/Krystal/View/Krystalview4.mp4",
        "Videos/Krystal/View/Krystalview5.mp4",
        "Videos/Krystal/View/Krystalview6.mp4",
        "Videos/Krystal/View/Krystalview7.mp4",
        "Videos/Krystal/View/Krystalview8.mp4"
    ]>>
    Krystal stands tall, her posture proud yet subdued. She’s clearly aware of her strength and beauty, but the subtle lowering of her head betrays her recognition of your dominance. Though she doesn’t look directly at you, it’s obvious she’s waiting for your next move, ready to follow your orders with a quiet grace that contrasts with her inner pride.

<<elseif _creature.name == "Raven">>
    <<set _videos = [
        "Videos/Raven/View/Ravenview1.mp4",
        "Videos/Raven/View/Ravenview2.mp4",
        "Videos/Raven/View/Ravenview3.mp4",
        "Videos/Raven/View/Ravenview4.mp4",
        "Videos/Raven/View/Ravenview5.mp4"
    ]>>
    You step into the training room, the air thick with anticipation. Raven is already there, standing at attention, her eyes fixed on you with an intensity that is almost unnerving. Her naked body is tense, every muscle poised for your command. The dim light casts shadows that highlight the curves of her form, making her look like a statue of pure, unadulterated desire.

    She inhales sharply, her breath hitching as she waits for your next move. Her eyes, though silent, convey an unspoken hunger, a craving for whatever you have in mind.
<</if>>

<<set _selectedVideo = _videos.random()>>

<!-- Display the selected video with autoplay and loop -->
<<= '<video src="' + _selectedVideo + '" autoplay loop controls style="width: 100%; max-width: 800px; height: auto;"></video>'>>

- HP: <<print _creature.currentHP>> / <<print _creature.maxHP>>
- Attack Damage: <<print _creature.damage>>
- Relationship: <<print _creature.relationship>>

What would you like to do?

<!-- Links to separate passages -->
[[Watch from across the room->WatchCreature]]

<<if _creature.relationship >= 10>>
    [[Hug->HugCreature]]
<<else>>
    You need a relationship level of 10 or higher to hug <<print _creature.name>>.
<</if>>

<<if _creature.relationship >= 30>>
    [[Feed->FeedCreature]]
<<else>>
    You need a relationship level of 30 or higher to feed <<print _creature.name>>.
<</if>>

<<if _creature.relationship >= 70>>
    [[Missionary Sex ->SleepWithCreature]]
<<else>>
    You need a relationship level of 70 or higher to access this event with <<print _creature.name>>.
<</if>>

<<if _creature.relationship >= 80>>
    [[Anal From behind ->Anal From Behind]]
<<else>>
    You need a relationship level of 80 or higher to access this event with <<print _creature.name>>.
<</if>>

<!-- Equip option based on relationship level -->
<<if _creature.relationship >= 100 and not _creature.equipped>>
    <<link "Equip <<print _creature.name>> for Battle">>
        <!-- Unequip any currently equipped creature -->
        <<for _c range $creatures>>
            <<if _c.equipped>>
                <<set _c.equipped = false>>
                <<set $creatures[$creatures.indexOf(_c)] = _c>>
            <</if>>
        <</for>>

        <!-- Equip the selected creature -->
        <<set $creatures[$creatures.indexOf(_creature)].equipped = true>>
        <<goto "ViewCreature">>
    <</link>>
<</if>>
<<if _creature.equipped>>
    <<print _creature.name>> is currently equipped for battle.
<</if>>

[[Back to Training Area->TrainingArea]]
I can grab info out of the array like this below but it only works for a limited number of times (set manually)
HTML:
<<set _creature1 = $creatures[0]>>
<<if _creature1>>
    <<set _creatureID1 = _creature1.id>>

    <!-- Display the first creature's details -->
    <<link _creature1.name>>
        <<set $currentCreatureID = _creatureID1>>
        <<goto "ViewCreature">>
    <</link>>
    (ID: <<print _creatureID1>>)
    - HP: <<_creature1.currentHP>> / <<_creature1.maxHP>>
    - Attack Damage: <<_creature1.damage>>
    - Relationship: <<_creature1.relationship>>

    <!-- Equip option based on relationship level -->
    <<if _creature1.equipped>>
        (Equipped for battle)
    <<elseif _creature1.relationship >= 100>>
        <<link "Equip for battle">>
            <<set $currentCreatureID = _creatureID1>>
            <<goto "EquipCreature">>
        <</link>>
    <</if>>
    <<print "\n">>
<</if>>

<<set _creature2 = $creatures[1]>>
<<if _creature2>>
    <<set _creatureID2 = _creature2.id>>

    <!-- Display the second creature's details -->
    <<link _creature2.name>>
        <<set $currentCreatureID = _creatureID2>>
        <<goto "ViewCreature">>
    <</link>>
    (ID: <<print _creatureID2>>)
    - HP: <<_creature2.currentHP>> / <<_creature2.maxHP>>
    - Attack Damage: <<_creature2.damage>>
    - Relationship: <<_creature2.relationship>>

    <!-- Equip option based on relationship level -->
    <<if _creature2.equipped>>
        (Equipped for battle)
    <<elseif _creature2.relationship >= 100>>
        <<link "Equip for battle">>
            <<set $currentCreatureID = _creatureID2>>
            <<goto "EquipCreature">>
        <</link>>
    <</if>>
    <<print "\n">>
<</if>>

<<set _creature3 = $creatures[2]>>
<<if _creature3>>
    <<set _creatureID3 = _creature3.id>>

    <!-- Display the third creature's details -->
    <<link _creature3.name>>
        <<set $currentCreatureID = _creatureID3>>
        <<goto "ViewCreature">>
    <</link>>
    (ID: <<print _creatureID3>>)
    - HP: <<_creature3.currentHP>> / <<_creature3.maxHP>>
    - Attack Damage: <<_creature3.damage>>
    - Relationship: <<_creature3.relationship>>

    <!-- Equip option based on relationship level -->
    <<if _creature3.equipped>>
        (Equipped for battle)
    <<elseif _creature3.relationship >= 100>>
        <<link "Equip for battle">>
            <<set $currentCreatureID = _creatureID3>>
            <<goto "EquipCreature">>
        <</link>>
    <</if>>
    <<print "\n">>
<</if>>

[[Back to Hub->HubArea]]
The reason is that you don't pass the value of the creature ID since it keeps updating within the loop.

I haven't used capture myself, but I think this should work:
HTML:
<<for _creature range $creatures>>
    <<set _creatureID = _creature.id>>
    <!-- Link to the single ViewCreature passage and pass the creature ID -->
    <<capture _creatureID>>
        <<link _creature.name>>
            <<set $currentCreatureID = _creatureID>>
            <<goto "ViewCreature">>
        <</link>>
    <</capture>>
 
Last edited:

WiseGuyAnimates

Newbie
Game Developer
Oct 25, 2018
22
25
The reason is that you don't pass the value of the creature ID since it keeps updating within the loop.

I haven't used capture myself, but I think this should work:
HTML:
<<for _creature range $creatures>>
    <<set _creatureID = _creature.id>>
    <!-- Link to the single ViewCreature passage and pass the creature ID -->
    <<capture _creatureID>>
        <<link _creature.name>>
            <<set $currentCreatureID = _creatureID>>
            <<goto "ViewCreature">>
        <</link>>
    <</capture>>
alas, not quite some closing argument errors, I've tried adapting it but I'm still stuck, Currentcreatureid

Code:
:: TrainingArea
<<for _creature range $creatures>>
    <<capture _creatureID = _creature.id>>
        <!-- Link to the single ViewCreature passage and pass the creature ID -->
        <<linkappend _creature.name>>
            <<set $currentCreatureID = _creatureID>>
            <<goto "ViewCreature">>
        <</linkappend>>
       
        <!-- Display creature details -->
        - HP: <<print _creature.currentHP>> / <<print _creature.maxHP>>
        - Attack Damage: <<print _creature.damage>>
        - Relationship: <<print _creature.relationship>>

        <!-- Equip option based on relationship level -->
        <<if _creature.equipped>>
            (Equipped for battle)
        <<elseif _creature.relationship >= 100>>
            <<linkappend "Equip for battle">>
                <<set $currentCreatureID = _creatureID>>
                <<goto "EquipCreature">>
            <</linkappend>>
        <</if>>

        <<print "\n">>
    <</capture>>
<</for>>

[[Back to Hub->HubArea]]
now the currentCreatureID is undefined when you click the link to the next passage, again, it displays properly on the Trainingarea
HTML:
:: ViewCreature
<<if $currentCreatureID>>
    <<set _creature = $creatures.find(c => c.id == $currentCreatureID)>> <!-- Find the creature using the ID -->

    <<if _creature>>
        **<<print _creature.name>>**
 

WiseGuyAnimates

Newbie
Game Developer
Oct 25, 2018
22
25
Got it!

HTML:
:: TrainingArea
<<for _creature range $creatures>>
    <<capture _creature>>
        <!-- Link to the single ViewCreature passage and pass the creature ID -->
        <<linkappend _creature.name>>
            <<set $currentCreatureID = _creature.id>>
            <<goto "ViewCreature">>
        <</linkappend>>
        
        <!-- Display creature details -->
        - HP: <<print _creature.currentHP>> / <<print _creature.maxHP>>
        - Attack Damage: <<print _creature.damage>>
        - Relationship: <<print _creature.relationship>>

        <!-- Equip option based on relationship level -->
        <<if _creature.equipped>>
            (Equipped for battle)
        <<elseif _creature.relationship >= 100>>
            <<linkappend "Equip for battle">>
                <<set $currentCreatureID = _creature.id>>
                <<goto "EquipCreature">>
            <</linkappend>>
        <</if>>

        <<print "\n">>
    <</capture>>
<</for>>

[[Back to Hub->HubArea]]
 

Alcahest

Engaged Member
Donor
Game Developer
Jul 28, 2017
3,405
4,238
Got it!

HTML:
:: TrainingArea
<<for _creature range $creatures>>
    <<capture _creature>>
        <!-- Link to the single ViewCreature passage and pass the creature ID -->
        <<linkappend _creature.name>>
            <<set $currentCreatureID = _creature.id>>
            <<goto "ViewCreature">>
        <</linkappend>>
     
        <!-- Display creature details -->
        - HP: <<print _creature.currentHP>> / <<print _creature.maxHP>>
        - Attack Damage: <<print _creature.damage>>
        - Relationship: <<print _creature.relationship>>

        <!-- Equip option based on relationship level -->
        <<if _creature.equipped>>
            (Equipped for battle)
        <<elseif _creature.relationship >= 100>>
            <<linkappend "Equip for battle">>
                <<set $currentCreatureID = _creature.id>>
                <<goto "EquipCreature">>
            <</linkappend>>
        <</if>>

        <<print "\n">>
    <</capture>>
<</for>>

[[Back to Hub->HubArea]]
Your first attempt didn't work because you for some reason tried to set the value inside the capture, which results in an undefined value. If you set it before like I did (or just capture _creature.id), it should work. No need to capture the entire creature. :)
 
Last edited:

guest1492

Member
Apr 28, 2018
335
278
Two things I want to point out:
  1. Wouldn't it be a lot easier to just save the index of the creature in the array rather than to look it up later using one of its property values?
  2. Why are you using the linkappend macro when you only use them as navigation links?
HTML:
:: TrainingArea
<<for _i, _creature range $creatures>>
    <<capture _i>>
        <!-- Link to the single ViewCreature passage and pass the creature ID -->
        [[_creature.name|ViewCreature][$currentCreatureIndex = _i]]
        
        <!-- Display creature details -->
        - HP: <<print _creature.currentHP>> / <<print _creature.maxHP>>
        - Attack Damage: <<print _creature.damage>>
        - Relationship: <<print _creature.relationship>>

        <!-- Equip option based on relationship level -->
        <<if _creature.equipped>>
            (Equipped for battle)
        <<elseif _creature.relationship >= 100>>
            [[Equip for battle|EquipCreature][$currentCreatureIndex = _i]]
        <</if>>

        <br>
    <</capture>>
<</for>>

[[Back to Hub->HubArea]]


:: ViewCreature
<<set _creature = $creatures[$currentCreatureIndex]>>
<!-- Stuff -->
 

Alcahest

Engaged Member
Donor
Game Developer
Jul 28, 2017
3,405
4,238
  1. Why are you using the linkappend macro when you only use them as navigation links?
I think it's because linkappend was used in the usage example for <<capture>> in the SugarCube manual.
 

WiseGuyAnimates

Newbie
Game Developer
Oct 25, 2018
22
25
Two things I want to point out:
  1. Wouldn't it be a lot easier to just save the index of the creature in the array rather than to look it up later using one of its property values?
  2. Why are you using the linkappend macro when you only use them as navigation links?
HTML:
:: TrainingArea
<<for _i, _creature range $creatures>>
    <<capture _i>>
        <!-- Link to the single ViewCreature passage and pass the creature ID -->
        [[_creature.name|ViewCreature][$currentCreatureIndex = _i]]
       
        <!-- Display creature details -->
        - HP: <<print _creature.currentHP>> / <<print _creature.maxHP>>
        - Attack Damage: <<print _creature.damage>>
        - Relationship: <<print _creature.relationship>>

        <!-- Equip option based on relationship level -->
        <<if _creature.equipped>>
            (Equipped for battle)
        <<elseif _creature.relationship >= 100>>
            [[Equip for battle|EquipCreature][$currentCreatureIndex = _i]]
        <</if>>

        <br>
    <</capture>>
<</for>>

[[Back to Hub->HubArea]]


:: ViewCreature
<<set _creature = $creatures[$currentCreatureIndex]>>
<!-- Stuff -->
Yeah, the reason its the link append is because when i asked a guy on redit how to use the capture he had link append in it and i didnt want to change too much the first time using it. And the rest is literally the first way i thought up doing it and it works so i probably won't change it.