 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Fri Feb 09, 2007 1:10 pm Post subject: Problems with an OnKeyPress script |
|
|
I have absolutely NO freaking clue what I'm doing wrong here, but for some reason, it just doesn't work right. This is a script for my options screen in an RPG I'm making (you may've seen the 'OPTIONS' screen from a previous thread I started), and you're supposed to be able to change the color of textboxes by pressing up or down to increase/decrease the red/green/blue in a color. HOWEVER, whenever I press 'up', instead of increasng by 1, it increases by 2 — and pressing 'down' does nothing.
Code for this is below:
Code: | #################################################
include, plotscr.hsd
include, scancode.hsi
#################################################
# HamsterSpeak constant definitions for ohrrpgce
define constant, begin
15,tag:a9gujow4t
end
#################################################
global variable (1,rememberhtbc-r)
#################################################
define script (1,Change Red Color,none)
script, Change Red Color, begin
set tag (15,on)
if (check tag (15) == on) then (if (key is pressed (72)) then (
write color (50,color:red,read color (50,color:red)+1)
update palette
clear string (1)
remember HTBC-R := read color (50,color:red)
show string at (1,200,32)
string style (1,string:flat)
string color (1,56,0)
clear string (1)
append number (1,remember HTBC-R)))
if (check tag (15) == on) then (if (key is pressed (80)) then (
write color (50,color:red,read color (50,color:red)--1)
update palette
clear string (1)
remember HTBC-R := read color (50,color:red)
show string at (1,200,32)
string style (1,string:flat)
string color (1,56,0)
clear string (1)
append number (1,remember HTBC-R)))
end
################################################# |
Download RPG file.
What am I doing wrong? :( Or is this a bug?
Last edited by Kizul Emeraldfire on Fri Feb 09, 2007 2:54 pm; edited 1 time in total |
|
Back to top |
|
 |
TwinHamster ♫ Furious souls, burn eternally! ♫

Joined: 07 Mar 2004 Posts: 1352
|
Posted: Fri Feb 09, 2007 2:34 pm Post subject: |
|
|
Well, it looks like the problem is that you have key 72 used twice.
But the way I'm reading it, it should increase the color by one and then decrease it by one. |
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Fri Feb 09, 2007 2:54 pm Post subject: |
|
|
Heh, whoops. ^^; Well, I corrected that error — and it still is broken the same way. :( |
|
Back to top |
|
 |
Iblis Ghost Cat

Joined: 26 May 2003 Posts: 1233 Location: Your brain
|
Posted: Fri Feb 09, 2007 3:32 pm Post subject: |
|
|
Quote: | Code: | set tag (15,on)
if (check tag (15) == on) |
|
Why bother checking whether the tag is on when you turn it on in the previous line? The tag will always be on here.
You also wouldn't need to define a constant for tag 15 if you had included your RPG's .hsi file. You don't ever seem to use the constant anyway though. You don't use any of the constants from scancode.hsi either. If you're going to refer to keys by their number you don't need scancode.hsi, that's only if you want to use the names of the keys.
You do "clear string (1)" twice in each if block and I don't see why.
None of those changes should make a functional difference, they'll just help the code make more sense. The only functional suggestion I have is to try tweak palette instead of write color. I seem to recall having some trouble with write color a while back. _________________ Locked
OHR Piano |
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Fri Feb 09, 2007 4:39 pm Post subject: |
|
|
Iblis wrote: | Quote: | Code: | set tag (15,on)
if (check tag (15) == on) |
|
Why bother checking whether the tag is on when you turn it on in the previous line? The tag will always be on here.
You also wouldn't need to define a constant for tag 15 if you had included your RPG's .hsi file. You don't ever seem to use the constant anyway though. |
The reason for this is simple: This is just a code snippet I took from a much larger script file, done up to be usable in a standalone RPG file (which is also linked to in my first post).
Iblis wrote: | You don't use any of the constants from scancode.hsi either. If you're going to refer to keys by their number you don't need scancode.hsi, that's only if you want to use the names of the keys. |
For some reason, I kept getting errors every time I tried to compile a keypress script without the Scancode.hsi being included. This was a couple of years ago, though, so I guess things might've changed. Also, another reason I changed it to the scancode numbers was because I thought that using the scancode constants was what was messing it up. :|
Iblis wrote: | You do "clear string (1)" twice in each if block and I don't see why. |
The reason for THAT is explained in this thread. Sort of.
Iblis wrote: | None of those changes should make a functional difference, they'll just help the code make more sense. The only functional suggestion I have is to try tweak palette instead of write color. I seem to recall having some trouble with write color a while back. |
Just tried using Tweak Palette — it seems to work fine now. Thanks! :D |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|