4
\$\begingroup\$

I'm trying to create a log of a players actions as they play a game of Spelunky. The easiest I've found to do this is to log what keys are pressed at each frame. What I don't know how to do is how to integrate this with the Game Maker source code of Spelunky.

Is there a specific way to create a script that is checked every frame/tick (don't know the right term) and a command to find what buttons are pressed?

\$\endgroup\$

2 Answers 2

6
\$\begingroup\$

I would store the keys and times as two ds_lists.

Create an object and call it keyLogger (or whatever). In the create event, create two lists:

keyCodes = ds_list_create();
keyTimes = ds_list_create();
frame = 0;

Then, in the step event, you can log the keys and advance time.

if(keyboard_check_pressed(vk_anykey))
{
    ds_list_add(keyCodes, keyboard_key);
    ds_list_add(keyTimes, frame);
}
frame += 1;

You can then draw all the keys in the draw event.

var i, s;
for(i = 0; i < ds_list_size(keyCodes); i += 1)
{
    s = "At frame ";
    s += string(ds_list_find_value(keyTimes, i));
    s += " you pressed key ";
    s += chr(ds_list_find_value(keyCodes, i));
    s += " (Code: ";
    s += string(ds_list_find_value(keyCodes, i));
    s += ")."
    draw_text(4, 4+i*20, s);
}

All you need to do is put this object in any room that you want to log keys in.

It should give an output that looks like this:

At frame 159 you pressed key F (Code: 14).

At frame 232 you pressed key 7 (Code: 95).

\$\endgroup\$
1
  • \$\begingroup\$ This is awesome thanks, the only issue I have is I also need to know how long a key was pressed, and if multiple keys are pressed at the same time. \$\endgroup\$ Mar 21, 2012 at 3:44
0
\$\begingroup\$

What might Be even simple but it could go bad, is if you logged the x and y of the character and stored then in a 2d array [frame,x or y Boolean value] then just repeat the sequence

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .