Makin a link refresh on the same page with (if:) involved

Hello again! :wink:

I think this time I have a more serious problem, or maybe not who knows? :sweat_smile:

In my game, I created a shop in which a player can buy weapons, shields, etc etc. At the beginning, the player has a set amount of money, but that amount is not enough to buy all things currently in the shop. In the earlier passage I’ve pasted this:

{
(set: $credits to 3000)
(set: $blaster2 to 0)
(set: $shieldprojector to 0)
}

And in the shop:

The most easiest things to find and buy on Nar Shaddaa were drugs, weapons, and anything banned for which one could get in serious trouble in worlds such as Coruscant or Corellia.

Many vendors of different species offered their merchandise to the locals and tourists. One small shop, owned by a blue-skinned Twi’lek male, sell advanced cybernetic implants of unknown origins.

A few shops further, an old greenish Toydarian male sell weapons and defensive technology. If I wanted to buy new weapons, defence gear, or recharge the power of

(if: $shieldprojector is 1)[ my shield projector,]\
(else:)[ an energy shield projector,]

his shop named Gerru’s Weaponry was the place to go.

I entered the shop and began to browse, while prices were relatively fair, I had to remember I had

(colour: orange)|credits>[$credits]

credits so I had to chose carefully.

‘’- Weapons -’’

While the Toydarian had a broad range of weapons, I wasn’t interested in rifles and other crowd-control weapons. I always carried one blaster with me since I would fell uncomfortable carrying more firearms. If anything, I could but myself a better blaster pistol.

{(if: $credits >=1200 and $blaster2 is 0)[(link: "DL-44 heavy blaster pistol")[(colour: yellow)[I bought the DL-44 heavy blaster pistol
(set: $blaster2 to 1)(set: $credits to it -1200)
(replace: ?credits)[$credits]]]]\
(if: $credits <1200)[(colour: yellow)[I don't have enough credits to buy the Dl-44 heavy blaster pistol]]\
(if: $blaster2 is 1)[(colour: yellow)[I already have the DL-44 heavy blaster pistol]] - a very expensive weapon, which was considered to be one of the most powerful blaster pistols in the galaxy. Cost: 1200 credits (13dmg - 17dmg per shoot)}

‘’- Defensive Technology -’’

{(if: $credits >=2500 and $shieldprojector is 0)[(link: "Personal energy shield projector")[(colour: yellow)[I bought the personal energy shield projector(set: $shieldprojector to 1)(set: $credits to it -2500)(replace: ?credits)[$credits]]]]\
(if: $credits <2500)[(colour: yellow)[I don't have enough credits to buy the personal energy shield projector]]\
(if: $shieldprojector is 1)[(colour: yellow)[I already have the personal energy shield projector]] - a defensive technology that projected a field of energy that protected the user from blaster fire, the elements, or other hazards. Most were small enough to be worn on a belt or arm, or were designed to be held much like a traditional physical shield. Cost: 2500 credits (100 shield power)}

[[back->merchant areas]]

The player has two links and when he clicks one, the amount of credits changes and the designated text in yellow colour appears. Everything works fine but there’s one problem. After clicking one link, the other one is still clickable despite that the player doesn’t have the right amount of money. He can still buy the second item and the amount of credits in orange changes to -$credits.

How to make so that if he doesn’t have enough money, the second link changes to the yellow text which points out that he doesn’t have the right amount of money? Something with replace and if maybe? :thinking:

You would use the same technique you are using to ‘refresh’ the displayed value of $credits, that being a Named Hook plus (replace:) macro combination.

Specifically, you would do the following:

1: Move the code that displays the actual links to a child Passage, in this example I will name that passage “Shop Item Links” (without quotes)

Some Weapon related text....

{
(if: _purchase is "DL-44")[
	(colour: yellow)[I bought the DL-44 heavy blaster pistol]
]
(else-if: $blaster2 is 1)[
	(colour: yellow)[I already have the DL-44 heavy blaster pistol]
]
(else-if: $credits < 1200)[
	(colour: yellow)[I don't have enough credits to buy the Dl-44 heavy blaster pistol]
]
(else:)[
	(link: "DL-44 heavy blaster pistol")[
		(set: _purchase to "DL-44")
		(set: $blaster2 to 1)
		(set: $credits to it - 1200)
		(replace: ?credits)[$credits]
		(replace: ?itemlinks)[(display: "Shop Item Links")]
	]
	- a very expensive weapon, which was considered to be one of the most powerful blaster pistols in the galaxy. Cost: 1200 credits (13dmg - 17dmg per shoot)
]
}

Some Defensive Technology relate text...

{
(if: _purchase is "PESP")[
	(colour: yellow)[I bought the personal energy shield projector]
]
(else-if: $shieldprojector is 1)[
	(colour: yellow)[I already have the personal energy shield projector]
]
(else-if: $credits < 2500)[
	(colour: yellow)[I don't have enough credits to buy the personal energy shield projector]
]
(else:)[
	(link: "DL-44 heavy blaster pistol")[
		(set: _purchase to "PESP")
		(set: $shieldprojector to 1)
		(set: $credits to it - 2500)
		(replace: ?credits)[$credits]
		(replace: ?itemlinks)[(display: "Shop Item Links")]
	]
	 - a defensive technology that projected a field of energy that protected the user from blaster fire, the elements, or other hazards. Most were small enough to be worn on a belt or arm, or were designed to be held much like a traditional physical shield. Cost: 2500 credits (100 shield power)
]
}

WARNING: For brevity sake the above example does not contain all the Textual content that your example did, you will need to add it back in. The above also may not display the links + description or work exactly as you require, but it should give you a better idea about what needs to be don’t functionally to achieve the result you require.

2: Replace the area within the ‘Shop’ related Passage, that used to contain the ‘link’ related code, with the following. It initialise the temporary variable being used to track what item was just purchased and sets up the Named Hook which will contain the ‘Item links’

(set: _purchase to "")
|itemlinks>[(display: "Shop Item Links")]

Yup, the links disappeared just like you said, but it gave me another idea. Thanks you for your help :smiley: