Triggering tags only the first time you get and Item?

Talk about things that are not making games here. But you should also make games!

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
maunderingcabal
Red Slime
Posts: 37
Joined: Sun Oct 30, 2016 8:49 am
Location: Hell, California
Contact:

Triggering tags only the first time you get and Item?

Post by maunderingcabal »

I have created and achievement system in my game. Is there a way to script an "If" statement to run only once after you get an item for the first time? Like this

Code: Select all

plotscript, item achievement, begin
If (check tag(tag:2, on)) then ( # tag to stop the script it the item has already been picked up before
 end)
 else (
 If (check tag(tag:1, on) then ( #tag 1 on if you have the item
 text box (1) #achievement
 wait for text box
 set tag (2, on))
end
Then somehow do a script for every time to check every time you close the menu or something?
Here is my OHRRPGCE Development Page: https://startru.wordpress.com. Follow us on Twitter @startruckerdev
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I was about to say you should use a second tag to show that the first tags action has already completed... Then I looked again at your script, and saw you had already done exactly that!

So you are doing it the right way. Is it working okay?
User avatar
maunderingcabal
Red Slime
Posts: 37
Joined: Sun Oct 30, 2016 8:49 am
Location: Hell, California
Contact:

Post by maunderingcabal »

Bob the Hamster wrote:I was about to say you should use a second tag to show that the first tags action has already completed... Then I looked again at your script, and saw you had already done exactly that!

So you are doing it the right way. Is it working okay?
I haven't tried it yet. By theory I think it will work for one, but I'm wondering if there is a way to do this for all my items, like 50-60 different tags for the items in one script. So every time someone gets an item for the first time it will trigger an achievement text?
Here is my OHRRPGCE Development Page: https://startru.wordpress.com. Follow us on Twitter @startruckerdev
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

Post by SwordPlay »

You could use variables. Something like:

variable (itemcheck)
variable (achievementstate)

## count through the items
FOR(itemcheck, start, finish)
DO (

## check what the state re: achievement is for this item)
SWITCH (achievementstate)
## don't have the item. This is the initial state.
CASE(0)DO(
IF(inventory (itemcheck))
## :=1 or +1
THEN(achievementstate:=1)
## have the item
CASE(1)DO( (show your achievement, variable:=2)
## shown achievement
CASE(2)DO (Achievement message shown, nothing happens)
)

Depending on how you configure your achievement pop-up, you could have it get the item name and/or description, combine with other strings, and generate the message rather than writing each one out.

You might simply have

"You got the X"
X = Item
e.g. "You got the Blue Key"


"You got the Y X"
Y = Item category
X = Item
e.g. "You got the Sword; Excalibur"


You might even have a list of descriptions, like this:
"You got the X! It's Y (and Z, etc.,)"
X = Item
Y, Z, etc., = Descriptions
e.g. "You got the Inferno Armour! It resists fire and lights up darkness"
e.g. "You got the Birthday Cake! You received it on the 21/07"
e.g. "You got the Godsoul. This is achievement 12/987."

Or make the whole message generated out of parts:
e.g. "You STOLE the Mayor's Keyring"
e.g. "You defeated the Swamp Ogre and got a Mud Pie"
e.g. "Earned the 1st place ribbon!"


You could even use slices to generate a designed template, and have it filled in with text and images.
Last edited by SwordPlay on Fri Aug 25, 2017 9:22 pm, edited 2 times in total.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

There are several mistakes in your (maunderingcabal's) script: "If (check tag(tag:2, on))" should be written "If (check tag(tag:2) == on)" (and actually the "== on" is completely unnecessary). And the if-then-else structure and placement of )/end's is wrong. Actually you should get rid of the 'else' and write "If (check tag(tag:2) == off)" instead. Finally instead of "tag:1" and "tag:2" you should put the real name of the tag, like "tag:achieved moondust"

But anyway for doing this all automatically instead of writing a different script for each item, to make more concrete what VSword said, you want to use an array. Normally I would use anarray of globals, but you could just as well use an array of tags. Lets say tags 1000+ are turned on once you have the achievement.

define constant(1000, item achievements)

Then you just want to loop over the items and check if you've gained one. Say you have up to 256 item definitions:

define constant(256, num items)

So the loop looks something like:

Code: Select all

plotscript, check item achievements, begin
  variable(item)
  for(item, 0, num items) do (
    if (check tag(item achievements + item) == false) then (  # don't have the achievement yet
      if (inventory(item) > 0) then (
        # Show some kind of message. See what Sword said for more detail; but this just shows the name:
        get item name(item, 1)
        show textbox(10)  # "Found the ${S1}"
        set tag(item achievements + item, on)
      )
    )
  )
end
Last edited by TMC on Sat Aug 26, 2017 1:38 am, edited 1 time in total.
Post Reply