Author Topic: Forcing a Keypress or Mouse Click  (Read 7426 times)

0 Members and 1 Guest are viewing this topic.

Offline Nostalgic

Forcing a Keypress or Mouse Click
« on: February 15, 2011, 08:06:01 PM »
One thing that's interesting about some SCI games is that you have to click a key or the mouse or whatever to get rid of the title screen. That's fine --- except for the fact that new players don't know that. I've experimented with a few games and people not familiar with these games routinely just sit there waiting for the title screen to go away.

Is there a way to simulate a key press after a given amount of time?

I've found a few threads that almost seem to answer this general question but they are usually talking about something else and so I'm not sure where to put the code or how to structure it.



Offline MusicallyInspired

Re: Forcing a Keypress or Mouse Click
« Reply #1 on: February 15, 2011, 09:07:54 PM »
You don't need to. You can have your script execute a command after a certain period of time. Use the changeState method in the RoomScript of your title screen. Something like this:

Code: [Select]
(method (changeState newState)
        = state newState
  (switch(state)
                     (case 0
(= seconds 10)
                     )(case 1
                                (send gRoom:newRoom(1))
                     )
                )
)

You can also use "cycles" instead of "seconds". Your changeState method is called as soon as the room's script is loaded. If there's nothing in the first case nothing happens. If you assign it a certain number of seconds or cycles it'll wait that long before going to the next case and execute any commands listed there. This is basically how you deal with any timed events in your game.
« Last Edit: February 15, 2011, 09:10:30 PM by MusicallyInspired »
Brass Lantern Prop Competition

Offline Cloudee1

Re: Forcing a Keypress or Mouse Click
« Reply #2 on: February 15, 2011, 09:17:08 PM »
Basicly it sounds like you want a changestate method. case 0 or the first state, you would simply set to a specific time, either in seconds or cycles before going to the next case, or rather state. in that next case, you aren't really faking a keypress, rather you are just making the same newroom call that the keypress is calling. the changestate method would be a part of the scripts public room instance, not  the init instance. a basic room has 2 instances, the init area and the actual public room instance. all interactions, events, or whatever occur in  that second instance... via the doit method, a changestate method, or the handleevent method.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline Nostalgic

Re: Forcing a Keypress or Mouse Click
« Reply #3 on: February 16, 2011, 05:31:51 AM »
Okay, so I basically had tried what you guys suggested. Here's how I modified the title screen logic of LockerGnome:

Code: [Select]
...
(case 5
Print("....")

(GameTitle:
init()
setPri(15)
setStep(0 8)
setCycle(Fwd)
setMotion(MoveTo 160 170)
)
= DISPLAY_AUTHOR TRUE
= cycles 10
)

(case 6
(send gRoom:newRoom(1))
//= CAN_CONTINUE TRUE
)
) // end switch(state)

Notice how I replaced the CAN_CONTINUE TRUE with the command you guys suggested? However, this precludes the following logic from the handleEvent method from running:

Code: [Select]
 (if(CAN_CONTINUE)
(send gRoom:newRoom(INITROOMS_SCRIPT))

And if I don't let that logic run, then any commands I type in the room aren't understood. For example, typing QUIT gives me "You've left me responseless."

If I take out the newly added line and just let CAN_CONTINUE TRUE run, then everything works as expected. Keep in mind that all this logic is being done in the TitleRoom screen of LockerGnome. That shouldn't make a difference I suppose, since it's a room just like any other.

Offline Cloudee1

Re: Forcing a Keypress or Mouse Click
« Reply #4 on: February 16, 2011, 05:09:45 PM »
I'll check out the code with your changes, but for now delete that (state) that comes after the )// end switch ... state is delared at the beginning of the changestate method. It actually represents the number of that case ... so (case 10 is actually state = 10, and in the second bit there should be one more ) right after the bit you posted to end the (if  statement. if there isn't you have misplaced it further down and that might be causing undesirable effects. Give me a bit I'll try to figure out whats going on.

* My bad, was viewing on my phone, the (switch) is fine, I thought it was on it's own line not part of the comment.

Ok, looked at the code and sticking the (send gRoom:newRoom(1)) in there is the problem... there are certain things which happen in between the title screen and the first room of the game. You'll notice that in Bri's if can continue bit of code, he sends the game to (send gRoom:newRoom(INITROOMS_SCRIPT)) ... this is a necesary step. You'll notice in your game going straight from the title screen to room 1, the menubar isn't drawn and you get the issues that you've got with nothing working right, not even quit. if you change that 1 to INITROOMS_SCRIPT, or 976, everything will work fine. In the initrooms script, is where you actually tell it to go to the first room of the game, after it's done it's bit to get everything ready.

so I guess to sum up, 
titlescreen -> initrooms -> any room in your game
« Last Edit: February 16, 2011, 06:51:30 PM by Cloudee1 »
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline Cloudee1

Re: Forcing a Keypress or Mouse Click
« Reply #5 on: March 01, 2011, 10:08:02 PM »
Did that solve your problem Nostalgic. If not, I noticed you played around with the variable names, maybe something else is going on
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline Nostalgic

Re: Forcing a Keypress or Mouse Click
« Reply #6 on: April 14, 2011, 01:44:21 PM »
Sorry for the delay in response. Yeah, that solved the problem nicely. Everything works as it should at this point.


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.083 seconds with 22 queries.