Register FAQ Search Today's Posts Mark Forums Read
Go Back   JazzJackrabbit Community Forums » Open Forums » JCS & Scripting

Help w/ script

Mike_1990

JCF Member

Joined: Mar 2012

Posts: 15

Mike_1990 is doing well so far

Apr 25, 2018, 01:09 PM
Mike_1990 is offline
Reply With Quote
Help w/ script

Could somebody skillful in scripting please help me with a scrip I'm working on?

I was thinking of making a shop in my levels, where you can browse items by pressing left and right. So I made a code that reads the input and stores integer depending on input and what item you're on (or so I thought). The problem is, as it is now, it cycles through items (just text right now) randomly. I know it's probably some stupid mistake but I'm not a programmer so...

Here's the code:

int shop_item;
void onPlayerInput(jjPLAYER@ player){
if (((player.yPos >= 42*32) && (player.yPos <= 44*32)) and ((player.xPos >= 146*32) && (player.xPos <= 148*32))){
if (jjKey[0x27] == true){
switch (shop_item){
case 0:
jjPlayers[32].showText("@@@@@Item1", STRING::SMALL);
shop_item = 1;
break;
case 1:
jjPlayers[32].showText("@@@@@Item2", STRING::SMALL);
shop_item = 2;
break;
case 2:
jjPlayers[32].showText("@@@@@Item3", STRING::SMALL);
shop_item = 3;
break;
case 3:
jjPlayers[32].showText("@@@@@Item4", STRING::SMALL);
shop_item = 4;
break;
case 4:
jjPlayers[32].showText("@@@@@Item5", STRING::SMALL);
shop_item = 5;
break;
case 5:
jjPlayers[32].showText("@@@@@Item1", STRING::SMALL);
shop_item = 1;
break;
}
}
if (jjKey[0x25] == true){
switch (shop_item){
case 0:
jjPlayers[32].showText("@@@@@Item1", STRING::SMALL);
shop_item = 1;
break;
case 1:
jjPlayers[32].showText("@@@@@Item5", STRING::SMALL);
shop_item = 5;
break;
case 2:
jjPlayers[32].showText("@@@@@Item1", STRING::SMALL);
shop_item = 1;
break;
case 3:
jjPlayers[32].showText("@@@@@Item2", STRING::SMALL);
shop_item = 2;
break;
case 4:
jjPlayers[32].showText("@@@@@Item3", STRING::SMALL);
shop_item = 3;
break;
case 5:
jjPlayers[32].showText("@@@@@Item4", STRING::SMALL);
shop_item = 4;
break;
}
}
}
}
Violet CLM Violet CLM's Avatar

JCF Éminence Grise

Joined: Mar 2001

Posts: 10,978

Violet CLM has disabled reputation

Apr 25, 2018, 07:38 PM
Violet CLM is offline
Reply With Quote
Looking good so far! Your problem is that jjKey[0x27] (and jjKey[0x25]) is true not only when the key on the keyboard is first pressed, but as long as it is pressed. Unless you can manage to touch the keyboard key for only a seventieth of a second, your script will change the value of shop_item more than once.
__________________
Mike_1990

JCF Member

Joined: Mar 2012

Posts: 15

Mike_1990 is doing well so far

Apr 25, 2018, 08:39 PM
Mike_1990 is offline
Reply With Quote
I see... The function seemed a little too good to be true I'll try to figure out some way how to limit recognition of input so it will make just one change.
Mike_1990

JCF Member

Joined: Mar 2012

Posts: 15

Mike_1990 is doing well so far

Apr 26, 2018, 09:17 AM
Mike_1990 is offline
Reply With Quote
Alright, got it now. Basically I've just added bool stop_select = true at the end of each case and if (stop_select != true) to the input conditions and then created another condition:

if ((jjKey[0x27] != true) and (jjKey[0x25] != true)){
stop_select = false;
}

So it stops reading input after first change and restores reading input as soon as player depresses left and right.

anyway thanks for reminding me how input function works.
Violet CLM Violet CLM's Avatar

JCF Éminence Grise

Joined: Mar 2001

Posts: 10,978

Violet CLM has disabled reputation

Apr 26, 2018, 09:55 AM
Violet CLM is offline
Reply With Quote
Glad to hear it's working!
__________________
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

All times are GMT -8. The time now is 06:45 AM.