I need help with a script.

Non-platform specific questions.

I need help with a script.

Postby ericdg » Tue Oct 31, 2006 7:09 pm

I don't have a lot of C knowledge so I need some help from all you code masters out there.

My question is about the RPN registration module code. As it is now when you enter the numbers for the reg code you click on them with your mouse.

I want to know how to be able to type in the reg code with your keyboard, so that when you hit 1, it shows 1, and when you hit 5 it shows 5 and so on.

Here is the script from the section I need help with.
Code: Select all
transp=0.99;
switch (cloneindex)
{
     case 0: strcpy(regchar,"0"); break;
       case 1: strcpy(regchar,"1"); break;
       case 2: strcpy(regchar,"2"); break;
       case 3: strcpy(regchar,"3"); break;
       case 4: strcpy(regchar,"4"); break;
       case 5: strcpy(regchar,"5"); break;
       case 6: strcpy(regchar,"6"); break;
       case 7: strcpy(regchar,"7"); break;
       case 8: strcpy(regchar,"8"); break;
       case 9: strcpy(regchar,"9"); break;
     case 10:
         strcpy(dummy,"");
         if (strlen(regaskcode)>0) strncat(dummy,regaskcode,strlen(regaskcode)-1);
         strcpy(regaskcode,dummy);
         PlaySound2("data/pop3.wav",soundvolume,1,0);
         break;
}

if (cloneindex<10) if (strlen(regaskcode)<5)
    {
        PlaySound2("data/click.wav",soundvolume,1,0);
                strcat(regaskcode,regchar);
    }






I originally thought each number was a seperate actor, which would be very easy to add a keydown event, but with each number being a clone of each other with the same script, I don't know how you would add a keydown event for each number.

Thanks everybody.
ericdg
 
Posts: 53
Joined: Tue Nov 29, 2005 1:18 pm
Score: 1 Give a positive score

Postby DilloDude » Wed Nov 01, 2006 3:13 am

Try using an any key event, and using getLastKey, and use that in the switch.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby ericdg » Thu Nov 02, 2006 12:19 pm

Ok, thanks.

Could you tell me real quick how to put that in the script above. I don't understand the switch function.

Could I put seperate code for each key, or do you think the getlastkey would be better?


BTW, dillodude, how is your game coming? It sounds great from what I've heard. I tried to download some of the game demos you posted but none of the links worked.

It sounds like your game could really benefit from the proposed multiplayer functions in future versions of game editor. I think that type of game would be great for multiplayer.
ericdg
 
Posts: 53
Joined: Tue Nov 29, 2005 1:18 pm
Score: 1 Give a positive score

Postby DilloDude » Fri Nov 03, 2006 7:56 am

For the switch part, use
Code: Select all
int key = getlastKey;
switch (key)
{
     case KEY_0: strcpy(regchar,"0"); break;
       case KEY_1: strcpy(regchar,"1"); break;
       case KEY_2: strcpy(regchar,"2"); break;
       case KEY_3: strcpy(regchar,"3"); break;
       case KEY_4: strcpy(regchar,"4"); break;
       case KEY_5: strcpy(regchar,"5"); break;
       case KEY_6: strcpy(regchar,"6"); break;
       case KEY_7: strcpy(regchar,"7"); break;
       case KEY_8: strcpy(regchar,"8"); break;
       case KEY_9: strcpy(regchar,"9"); break;
     case KEY_BACKSPACE:
         strcpy(dummy,"");
         if (strlen(regaskcode)>0) strncat(dummy,regaskcode,strlen(regaskcode)-1);
         strcpy(regaskcode,dummy);
         PlaySound2("data/pop3.wav",soundvolume,1,0);
         break;
}

for the next part, you would change it to:
Code: Select all
if (Key >= KEY_0 && key <= KEY_9) if (strlen(regaskcode)<5)
    {
        PlaySound2("data/click.wav",soundvolume,1,0);
                strcat(regaskcode,regchar);
    }

put it on a keydown for any key, at least one key pressed, with repeat disabled.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby ericdg » Sat Nov 04, 2006 10:27 pm

Wow, thanks.

If you don't mind me asking, how did you learn so much about C? Is it just something you have been doing for awhile, or is it something you learned in classes or books.

I'm trying to expand my C knowledge, but it just takes so much time.
ericdg
 
Posts: 53
Joined: Tue Nov 29, 2005 1:18 pm
Score: 1 Give a positive score

Postby DilloDude » Sat Nov 04, 2006 11:21 pm

I had some general programming knowledge for some time, as a result of having two brothers and a dad who do a fair bit of it, but I didn't really know exactly how to put it together properly, but when I got GE (sometime early this year), I began to develop that knowlede, through the tutorials to some extent and from from looking at web sites but mostly from all the helpful people on these forums.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby ericdg » Sun Nov 05, 2006 12:15 am

Dillodude, I have a question about the script given.

I changed the first part
Code: Select all
int key = getlastKey;
switch (key)


to
Code: Select all
int key = getLastKey();
switch (key)

to get it to work, but when I press a key it makes all 5 digits the same number with one press.

I do have repeat disabled and I even tried it with a key up event and it does the same thing, any ideas?
ericdg
 
Posts: 53
Joined: Tue Nov 29, 2005 1:18 pm
Score: 1 Give a positive score

Postby ericdg » Sun Nov 05, 2006 12:51 am

Disregard last post.

It must have been a bug. When I used it with a mousedown event it worked, but it did the 5 digits with a keydown event.

I split the code for each number as a keydown event and it worked, so I put the original code back as an any key keydown event and it works fine now.

Strange.

Thanks.
ericdg
 
Posts: 53
Joined: Tue Nov 29, 2005 1:18 pm
Score: 1 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest