i posted this before, but no one could help me...

Talk about making games.

i posted this before, but no one could help me...

Postby Kooldudese » Sat Jan 05, 2008 1:46 am

umm basictly its one of my old posts but no one could figure it out...
how do you make it so that theyre is a place where you can select what button you want to press to make that happen basicly in the options there is the
"controls"
of which in it it looks like
left=leftarrow "change key"
up=uparrow "change key"
down=downarrow "change key"
right=rightarrow "change key"
atk=spacebar "change key"
(and so on)
and when you press change key, it says"press the key to replace it"
plz help
(tell me if this is Impossible but i think it is because people have made games which could do this...(although not neccisarily with game editor...)
User avatar
Kooldudese
 
Posts: 128
Joined: Sat Jan 27, 2007 5:20 pm
Location: In a house
Score: 0 Give a positive score

Re: i posted this before, but no one could help me...

Postby DilloDude » Sat Jan 05, 2008 1:55 am

This is a fairly simple thing to do. I'm doing exactly the same thing in Super-Human. At the moment, I still need to set some stuff up, and then I'll have a look at it and tell you.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: i posted this before, but no one could help me...

Postby Bee-Ant » Sat Jan 05, 2008 9:03 am

Do you mean...CHANGEABLE CONTROL???
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: i posted this before, but no one could help me...

Postby Kooldudese » Sat Jan 05, 2008 3:22 pm

yes, changable control, thats what i want.
User avatar
Kooldudese
 
Posts: 128
Joined: Sat Jan 27, 2007 5:20 pm
Location: In a house
Score: 0 Give a positive score

Re: i posted this before, but no one could help me...

Postby Kooldudese » Sat Jan 05, 2008 3:24 pm

ok, tell me how to do this though, or make a demo for me when you have time... please this is a big part of my game, and without it my games pretty much crap. :roll:
User avatar
Kooldudese
 
Posts: 128
Joined: Sat Jan 27, 2007 5:20 pm
Location: In a house
Score: 0 Give a positive score

Postby DilloDude » Sun Jan 06, 2008 6:38 am

Here is how I did it:
In my case I have eight keys to map. First you need to make a button animation to go in your options menu. Draw an array of buttons with labels on them for what they are. This is one frame of the animation. Then copy this frame multiple times, so that you have one frame for each button, plus one more frame. The first frame leave as it is. For all the other frames, modify one button so it looks pressed. Make sure these go in a logical order, starting with the top-left button and moving across to the right, moving back to the left and dropping down a line when you get to the end, just as you would write. In my case the buttons also have a slot to put a text which will say what key that function is currently assigned to. As an example I have included the first two frames of my animation below.

Create an actor for these buttons, in my case called 'Controls'. DO NOT receive events when out of vision - unless you want to.

Create a variable to hold the stored key information. Make it an integer, array of size one more than the number of buttons. Put it in a save group so the user doesn't have to always chose the controls. In my case I have cntrl[9] (Global, Integer, save in CONFIG)
Because the array has nine slots they will be numbered 0-8. This corresponds to the frame numbers of Controls. The zero slot is used to save wether the saved file exists, for when the game loads.

For accessing the controls, create some constants. Put these statements somewhere in Global Code. Mine looked like this:
Code: Select all
// for controlsav
#define JSET 1
#define USET 2
#define SSET 3
#define PSET 4
#define LSET 5
#define DSET 6
#define RSET 7
#define MSET 8


Now you will need two functions for remapping the keys. Add this somewhere in Global Code:
Code: Select all
//////////  KeyFuncts  //////////

//use this to assign to the configured keys.
void setKeys()
{
    //this bit sets the keys to something completely different, to avoid confusion.
    remapKey(KEY_c, 404);
    remapKey(KEY_UP, 404);
    remapKey(KEY_x, 404);
    remapKey(KEY_p, 404);
    remapKey(KEY_LEFT, 404);
    remapKey(KEY_DOWN, 404);
    remapKey(KEY_RIGHT, 404);
    remapKey(KEY_m, 404);
   
   //this bit remaps the functions to the configured keys.
    remapKey(cntrl[JSET], KEY_c);
    remapKey(cntrl[USET], KEY_UP);
    remapKey(cntrl[SSET], KEY_x);
    remapKey(cntrl[PSET], KEY_p);
    remapKey(cntrl[LSET], KEY_LEFT);
    remapKey(cntrl[DSET], KEY_DOWN);
    remapKey(cntrl[RSET], KEY_RIGHT);
    remapKey(cntrl[MSET], KEY_m);
}

//use this to reset all the keys to their normal position.
void resetKeys()
{
    int i;
    for (i = 0; i < 439; i ++)
    {
        remapKey(i, i);
    }
}


Now you have to do something with the Controls actor. Put this on Create Actor Event
Code: Select all
ChangeAnimationDirection("Event Actor", STOPPED);
CollisionState("Event Actor", DISABLE);
EventDisable("Event Actor", EVENTALL);

//check if file exists
cntrl[0] = 0;
loadVars("conf.shd", "CONFIG");//load file: change to your location and save group
if (cntrl[0] == 0)//if the file doesn't exist, enter default values for controls.
{
    cntrl[JSET] = KEY_c;
    cntrl[USET] = KEY_UP;
    cntrl[SSET] = KEY_x;
    cntrl[PSET] = KEY_p;
    cntrl[LSET] = KEY_LEFT;
    cntrl[DSET] = KEY_DOWN;
    cntrl[RSET] = KEY_RIGHT;
    cntrl[MSET] = KEY_m;
}
setKeys();

Create a global integer to stor which key is being changed. I called it 'assign'.
In Draw Actor for Controls, put
Code: Select all
animpos = assign;
This makes it display the appropriate depressed button.
Add a Key Down event, any key:
Code: Select all
if (assign)//if we are waiting to assign a key.
{
    cntrl[assign] = getLastKey();//set the desired control
    assign = 0;//stop assigning
}

Now the fun part - Mouse Button down (left button) You will need to change some of these numbers based on the size of your buttons.
Code: Select all
//basically, this bit is to find which button was clicked, based on the mouse's x and y coordinates.
char pos;
screen_to_actor(&xmouse, &ymouse); xmouse += 268; ymouse += 107;
pos = (int)(xmouse / 134.5) + (4 * (int)(ymouse / 105.5)) + 1;

if (pos == assign)//if you clicked an already depressed button, deselect it.
{
    assign = 0;
}
else//otherwise, select it
{
    assign = pos;
}


You will need to use resetKeys() when you open the controls menu and when you want to type anything. Otherwise, things will be confused. When you want to use the controls again, use setKeys.

To make the button display the currently assigned key, create a text actor, not repeating events when out of vision, and on Draw Actor use strcpy to set text to the desired key. In my case I made each button have a separate actor, but you could just clone an array of them. Then you'd use:
Code: Select all
strcpy(text, getKeyText(cntrl[cloneindex + 1]));



I hope that helps and that I didn't forget anything. If you have any problems, just ask. Just try to understand most of what's happening, or at least the concept, and that way you'll learn, and be able to think for yourself in future. I've tried to comment the code a fair bit, but if you have questions, then ask.
Attachments
ControlsExample.png
The first two frames of the control image
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: i posted this before, but no one could help me...

Postby Bee-Ant » Sun Jan 06, 2008 7:21 am

Whouah :shock:
It will make us confused...too much of lines... :lol: :roll:
Btw, I'm also still searching how to make changeable control...thanks Dill :D
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: i posted this before, but no one could help me...

Postby Kooldudese » Mon Jan 07, 2008 1:38 am

O-k ill will look at the code and see if i can make it work... i will reply again if i get it to work or if it doesent work for me, it might take me a while since the holidays over, i will have to TRY to make time to get to work on this, thanks again Dill! ah, and if it wont trouble you, could you give me a demo? it would help me to see it in action =P it helps me figure out the code, Thx again.
-kooldudese
User avatar
Kooldudese
 
Posts: 128
Joined: Sat Jan 27, 2007 5:20 pm
Location: In a house
Score: 0 Give a positive score

Re: i posted this before, but no one could help me...

Postby Kooldudese » Tue Jan 08, 2008 2:06 am

well, i have a few problems... first of all i cant seem to figure out how to relate the code


char pos;
screen_to_actor(&xmouse, &ymouse); xmouse += 268; ymouse += 107;
pos = (int)(xmouse / 134.5) + (4 * (int)(ymouse / 105.5)) + 1;

if (pos == assign)
{
assign = 0;
}
else//otherwise, select it
{
assign = pos;
}
with my game... could you explaim what you relate to what?
and also, i came up with an interesting glitch... in game editor, it dident show an error but when i tried to
go to game mode it said that there was a gitch, basictly it was this code

ChangeAnimationDirection("Event Actor", STOPPED);
CollisionState("Event Actor", DISABLE);
EventDisable("Event Actor", EVENTALL);


cntrl[0] = 0;
loadVars("conf.shd", "CONFIG");
if (cntrl[0] == 0)
{
cntrl[JSET] = KEY_c;
cntrl[USET] = KEY_UP;
cntrl[SSET] = KEY_x;
cntrl[PSET] = KEY_p;
cntrl[LSET] = KEY_LEFT;
cntrl[DSET] = KEY_DOWN;
cntrl[RSET] = KEY_RIGHT;
cntrl[MSET] = KEY_m;
}
setKeys();

it said that the setkeys() is an undifined function
User avatar
Kooldudese
 
Posts: 128
Joined: Sat Jan 27, 2007 5:20 pm
Location: In a house
Score: 0 Give a positive score

Re: i posted this before, but no one could help me...

Postby DilloDude » Wed Jan 09, 2008 10:23 pm

Here is a demo. It uses the exact same method I posted above.
click the smiley in the bottom corner to start, then click the one in the top corner to go back to the options.
Default Controls:
arrow keys: move
space: turn pink
left shift: turn transparent

If you have any questions about implementing to fit your circumstance, or any other questions, just ask (well what else would you do?)
Attachments
Control.zip
Here it is ;)
(48.01 KiB) Downloaded 127 times
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: i posted this before, but no one could help me...

Postby Bee-Ant » Wed Jan 09, 2008 10:25 pm

Nice demo...thanks anyway :D
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: i posted this before, but no one could help me...

Postby DST » Tue Apr 08, 2008 3:34 am

Thanks for the post, that script worked perfectly!
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: i posted this before, but no one could help me...

Postby Fuzzy » Tue Apr 08, 2008 5:55 am

Hey Dillo, try this:

Code: Select all
// for controlsav
enum SETS {
    JSET, USET, SSET, PSET, LSET, DSET,  RSET, MSET
};


but note that the first value is zero.. not one.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron