Creating a second and third response? (SOLVED)

Hey, I really am more of a writer than a coder, so I need some help.

I want to make an object that when you first speak to or look at it says one thing, the second time another, the third another, and so on. Right now all I can seem to make is a first time response. Can anyone here explain to me how I could make a sort of chain of responses like this?


Each response is only offered one time? Are they random? Is the order important? :)


The order would be important and each one should only be displayed once.


well if you want to speak to a person/object then it will already be done in a script, however for a look at description there's a drop down menu where you can change the description from text to a script. You will want it to be set to script for this.

Actually getting a sequence of responses isn't that hard after that, it's really a matter of making a counter to track what response you're on, then showing the correct one.

ie:

// this is the objects description section set to script
if (not HasAttribute (this, "count")) {
  // this triggers if the attribute named count doesn't exist, so the first time it's looked at. The quotation marks are needed as they tell quest the name is a string and not a variable
  msg ("This is what the player sees the first time they look at the object")
  this.count = 2
  }
if else ( GetInt (this, "count) = 2) {
  // this triggers the second time the object is looked at, I set the count to 2 just for clarity
  msg("This is what the player sees the second time they look at the object")
  this.count = 3
  }
else {
  //the else triggers when the other sections fail their check, in this case after all the other descriptions are used
  msg("This is the final description")
  }

You can also make the whole thing cycle by having the final description section set the count back to an earlier number, however if you want the first time description to be re-used you would actually need to create the "count" attribute outside this script so that it exists before the description check. In that case the first one would be the same trigger as the second but check if it equals whatever value you decide to start the counter at.


Is there any way to make it not reveal all at once? Right now it says
"This is what the player sees the first time they look at the object
This is what the player sees the second time they look at the object"
one right after another. When I look the first time, they are all revealed like a list.


hmm, are you putting them all into the same if/else tree? It should only display a single option when setup that way

edit: also are you using the online or offline editor?


I'm online. They were all in one window, so I spread them out, but now it just says
"Error running script: Error compiling expression '': SyntaxError: Unexpected end of fileLine: 1, Column: 1"

On the second go.
Ack, I'm lost.


I'll take a look at the online editor so I can give you a better description of how to get it working

EDIT: okay built this in the online editor and tested so this should work if you copy and paste this block of code into the description of an object with the description set to script

also the // marks set stuff as a comment, meaning they don't affect the code whatsoever, I just like to leave notes and explanations in my code, but they are not necessary.

if (not HasAttribute(this, "count")) {
  // object doesn't have a counter yet
  msg ("This is the first time description")
  this.count = 2
}
else if (this.count = 2) {
  // when looked at after the first time
  msg ("Second look description")
  this.count = 3
}
else {
  // final message
  msg ("This is the final description")
}

Well this ended up being not quite as straight forwards as I thought, mainly due to not having an option to say "object does not have "x" attribute" as a preset expression. However you can do the "object has attribute" then jump to the code view and add in the "not" yourself

Anyways step by step

First I set the object description to script type
then add an "if" statement
for the expression I just manually entered 'not HasAttribute(this, "count")' or you can do as I said before this section
inside the first 'if' block, you need two things. First print a message, as this is the part the player will see. Second you need to do 'set a variable or attribute' which allows you to enter 'this.count = 2'.

  • you can use the object's name instead of "this" but "this" always points to the object that owns the script so any name changes wont break it. Also if you don't do 'something.variable' then the variable disappears when the script ends instead of being given to the object itself

At this point you now have a one time description that will just show nothing after the first look.
Under the box that contains everything belonging to the first "if" block, should be a button that says "add else if"
That button adds a new block that's part of the same "if" statement and has it's own conditions
In the new block we set the condition to "object attribute equals"
set the object box to 'this' , the attribute to 'count' and equal to '2'
after this we need the same two things as the first "if" block
a print message for the description text, and a set variable to change the trigger for which description the player sees

repeat the above section for the 'else if' as many times as needed, while changing the value of "count" that triggers it of course
finally you can end with an 'else' block
'else' is what happens when all other conditions fail, or in this case when every other description has been used up
add a print message with your final description
nothing else is needed here as the description won't be changing at this point
if you wanted it to return to an earlier point in the cycle just set 'count' to an earlier value

You now have a description that changes each time the player looks at it until it reaches the end.


Thank you so much! This totally worked.
I hope you have a good day.


You're welcome


Very useful for me too. Thank you.


People are too nice here!


we got a small but very friendly/helpful community :D


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums