Apr 25, 2018, 12:09 PM | |
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; } } } } |
Apr 25, 2018, 06:38 PM | |
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.
|
Apr 26, 2018, 08:17 AM | |
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. |
Apr 26, 2018, 08:55 AM | |
Glad to hear it's working!
|
![]() |
«
Previous Thread
|
Next Thread
»
Thread Tools | |
|
|
All times are GMT -8. The time now is 02:11 PM.
Jazz2Online © 1999-INFINITY (Site Credits). Jazz Jackrabbit, Jazz Jackrabbit 2, Jazz Jackrabbit Advance and all related trademarks and media are ™ and © Epic Games. Lori Jackrabbit is © Dean Dodrill. J2O development powered by Loops of Fury and Chemical Beats. Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Original site design by Ovi Demetrian. DrJones is the puppet master. Eat your lima beans, Johnny.