Non-threaded

Forums » Advanced Editor Forum » Read Thread

Get help from the experts on variables, scripts, items, and other scary things.

"Refill" Items

7 years ago
In TOW, the water pouch item can be used twice for it's effect of healing and can't be used again until the water pouch is refilled. The item stays in the inventory whether it's empty, half-empty, or full. How was this done? I want to make an item with a similar effect.

"Refill" Items

7 years ago

Make a variable (e.g. %VAR) for the item and set its value to the number of uses. Then you can, for instance, put "You can use this item %%VAR%% time%%VAR%=%1%s%%." in the description so the user knows how many uses they have left. Then for the item script:

IF %VAR > 0 THEN BEGIN
%HP := %HP + 10
$DEST := "@P" + $PAGEID
(or whatever code)
%VAR := %VAR - 1
END

And just reset the variable as needed.

"Refill" Items

7 years ago
Excuse my lack of knowledge in this field, but what does this do?:
$DEST := "@P" + $PAGEID

"Refill" Items

7 years ago

Answer

Read from the destination section onward.

"Refill" Items

7 years ago
Ah. I vaguely remember reading that article, but found it hard to understand at first, and I don't completely understand it even now.

So... translated, would the code be the following:

If Variable is greater then zero, then begin
Set Health to Health+10
Set Current Destination to Page#
Set Variable to Variable-1
End

Right?

And my question was kind of: What's the point of the: $DEST := "@P" + PageID

(Sorry ^^; I'm just trying to understand the 'why' of this. :S)

"Refill" Items

7 years ago

I think he's probably just showing that your item might have other effects besides just replenishing health. If your item doesn't need to send the user anywhere, then you can totally omit that line. I haven't CYS tested this so I could be wrong since I haven't scripted in literally half a decade.

"Refill" Items

7 years ago
Oh. That makes much more sense! So giving the item this effect was just tweaking a few variables. Thanks for your guys' help!

"Refill" Items

7 years ago

No worries!

Also, what you did when you translated the code to natural language is an awesome thing to do and if you ever end up pursuing computer science as more than just a hobby, you'll end up doing a lot of that.

"Refill" Items

7 years ago
That's a relief! I end up translating the script most of the time, and I thought it was because I was just bad with them because I couldn't just "get it".

"Refill" Items

7 years ago

I'll usually add $DEST := "@P" + $PAGEID on items to remove the pop-up, "The item cannot be used here." It seems to pop up regardless of whether you can trigger the script or not. By adding it like Bradin did, it'll prevent the pop-up when you can use the item, but allow it when you can't use it. 

If you want to stop people from accidentally using a consumable when they're already at full health, you can add a second layer of logic to it. You also want to make sure their health doesn't go over the max health, making it only fill up what's missing if they have less than the full heal amount gone. It'd roughly work like this:

If variable is greater than 0 then
If current health is less than max health then 
BEGIN
Set health to health + 10
Set variable to variable - 1
If health is greater than max health then
health := max health
Set destination to current page
END

"Refill" Items

7 years ago

Ah! That's a really clever work around! I didn't realize that $PAGEID was a system variable and that he was redirecting to the same page.

"Refill" Items

7 years ago
Also, you can work with the item used variable that is already in the system in some ways.

"Refill" Items

7 years ago

You can, and it is arguably simpler, but then the item is auto-hidden when used up and it isn't as easy to indicate how many uses are left.

"Refill" Items

7 years ago

OMG YES!!

I was so happy when it worked. x3 thanks everybody C: