ID:1139557
 
(See the best response by Jemai1.)
Hai, I tried to do some research on this but I couldn't find much. (Gave up after searching through the places I know to look.) And I am wondering if it is possible to do the thing which I am about to describe.

In the code below, you can see it is very basic. What I want to look at is the sleep proc. I want to know if it is possible to either A, set the sleep proc to wait until keyboard input is given from the user, or B, I can make the program wait at a point like this until keyboard input is given. Like, the first message would display, the user would press "A" or some more sensible key, and the next set of text would display.

I'm probably just missing something extremely obvious that would make this incredibly easy on me, but I wouldn't really be me if I didn't do that. XD

Code:
world << "Hai"
sleep(10)
World << "How are you?"




Galactic Soldier wrote:
Both are easily accomplished, but not with the sleep() procedure; you could make your own if you'd like. It's not hard to do fundamentally. You should learn how to program.

You are so wonderfully helpful my good sir, now if only you could help me out with my question instead of telling me "You should learn how to program." Or at the very least, do what is probably the best thing, and point me to exactly where I can learn these things?
Galactic Soldier wrote:
That all depends on how you want to handle it. You could make internal keyboard events, and chain it with procedures that are going to change a variable to make it stop sleeping, or you could handle it with referenced variables and javascript.

Woah, I didn't expect an answer from you after that first post. XD Thanks! I'm afraid I don't fully understand, but that is something for me to work with, and I shall try and figure stuff out.

o.o That would also be very appreciated!
*Whistles to self*
Best response
You can make a "Sleeper" datum to make your proc sleep then delete it to stop your proc from sleeping.

For example,
Sleeper
proc/Sleep()
for()
sleep(36000)

mob
var/Sleeper/sleeper

verb/Test()
sleeper = new
src << "Use the Stop verb."
sleeper.Sleep()
src << "Sleep ended."

verb/Stop()
if(sleeper) del sleeper

The trick here is that when a datum is deleted, all of its proc will return immediately. This includes our Sleeper's Sleep() proc.
That is interesting, don't think I would've ever thought of that. (That probably comes from me still being a novice programmer) Thanks!
Galactic Soldier wrote:
You should learn how to program.

You should learn how to post.

Cccel wrote:
That is interesting, don't think I would've ever thought of that. (That probably comes from me still being a novice programmer) Thanks!

Honestly I wouldn't have thought of it either :) That's sort of a tricky technique but I think it could be very useful in certain situations...

I'd like to ask, what is the situation that you want to wait for keyboard input? For your simple example, you could just have a verb (and a macro to activate it) that displays the next message:

mob
var/next_message = "Hai"

verb/view_message()
usr << next_message
next_message = "How are you?"


Obviously this wouldn't be very useful in an actual game, but I can imagine using lists to have this kind of function for conversations or other "scrolling" text:

var
conversation1 = list("Hai", "How are you?", "Nice weather today")
conversation2 = list("I'm bored...", "Yup, still bored...")

mob
var/index = 1 //these variables will allow the mob to "remember" where
var/my_convo = null //it was in a conversation, if any

verb/view_conversation()
if(my_convo == null) //if we dont have a current conversation, pick one
my_convo = pick(conversation1, conversation2)
usr << my_convo[index] //output one element from the list
index += 1 //next time the verb is called, the next element will be displayed
if(index > my_convo.len) //unless the index has gone past the number of elements in the list
my_convo = null //in which case, reset the variables
index = 1


anyway I'm not sure exactly what you are trying to do but with this sort of method you can plug in lists with any number of strings, instead of hard-coding when to stop displaying messages.


In response to Magicsofa
Magicsofa wrote:
Honestly I wouldn't have thought of it either :) That's sort of a tricky technique but I think it could be very useful in certain situations...

I'd like to ask, what is the situation that you want to wait for keyboard input?

In an attempt to completely ignore one of Byond's most useful features, I'm attempting a single player game. The intention of this is so that the player can progress a cutscene themselves, before this I had it set on a timer and it was a bit cumbersome to time things like that correctly. (In a way that made sense for what was being said, and how it should be replied to. That sense make? I no word good.)

Magicsofa wrote:
I can imagine using lists to have this kind of function for conversations or other "scrolling" text:

> var
> conversation1 = list("Hai", "How are you?", "Nice weather today")
> conversation2 = list("I'm bored...", "Yup, still bored...")
>
> mob
> var/index = 1 //these variables will allow the mob to "remember" where
> var/my_convo = null //it was in a conversation, if any
>
> verb/view_conversation()
> if(my_convo == null) //if we dont have a current conversation, pick one
> my_convo = pick(conversation1, conversation2)
> usr << my_convo[index] //output one element from the list
> index += 1 //next time the verb is called, the next element will be displayed
> if(index > my_convo.len) //unless the index has gone past the number of elements in the list
> my_convo = null //in which case, reset the variables
> index = 1
>


That does look like it would be very helpful, and could probably work pretty well. Thanks for including that, I shall note it for future reference. XD Anyway, for my purpose I think both could work. But the first solution I think will work a bit better for me, it was rather easy to implement. (Not that yours wouldn't be easy to implement. XD) I think it would also be a bit easier to use for the method in which I go about things.