Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Question involving using Strings to display a value
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
Kizul Emeraldfire
Type: Cyber Dragoon




Joined: 26 Mar 2004
Posts: 229

PostPosted: Thu Sep 14, 2006 4:36 pm    Post subject: Question involving using Strings to display a value Reply with quote

How do I make NPCs to display a value (say, the amount of red in the 192nd color on the palette) at a certain X,Y spot on a map (like in a custom battle system)?

Or would I be able to do this with strings?

Also, would it be possible to write the values to global variables?


Last edited by Kizul Emeraldfire on Mon Sep 25, 2006 7:18 pm; edited 1 time in total
Back to top
View user's profile Send private message Yahoo Messenger
Gizmog1
Don't Lurk In The Bushes!




Joined: 05 Mar 2003
Posts: 2257
Location: Lurking In The Bushes!

PostPosted: Thu Sep 14, 2006 5:21 pm    Post subject: Reply with quote

I'm not 100% sure what you mean. You can use global variables to allow the user to customize his palette, and have those changes save to the game, but as for displaying the amount of Red in a color in the palette, I always just used a variable, and show value. Just have the script set the actual value in the palette to be the same as the variable, and it should work okay, but it might not be exactly what you were thinking of.
Back to top
View user's profile Send private message Send e-mail AIM Address
TwinHamster
♫ Furious souls, burn eternally! ♫




Joined: 07 Mar 2004
Posts: 1352

PostPosted: Thu Sep 14, 2006 5:50 pm    Post subject: Reply with quote

If you want to position the variable, I'd suggest using textboxes.

As seen in Moogle's darkmoor dungeon, the selection of heroes is pretty much what you're trying to accomlish, except you're going to use the same text box over and over again.

Ex)

textbox (1)=
______________________
Color: ${V#}
______________________

while this textbox is shown, you want to suspend box advance.

Then stick the text box into a keypress script.

So, if you press up, the value is increased by one and textbox (1) is shown again, this time with the new, increased value.
Back to top
View user's profile Send private message Send e-mail AIM Address
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Thu Sep 14, 2006 5:54 pm    Post subject: Reply with quote

You can do this with strings -or- store them in globals and use textboxes instead. If you need more than one set onscreen at a time, use strings.

Someone who has messed around with strings can probably tell you the exact syntax better than I can.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
Kizul Emeraldfire
Type: Cyber Dragoon




Joined: 26 Mar 2004
Posts: 229

PostPosted: Thu Sep 14, 2006 5:59 pm    Post subject: Reply with quote

Gizmog1 wrote:
I'm not 100% sure what you mean. You can use global variables to allow the user to customize his palette, and have those changes save to the game, but as for displaying the amount of Red in a color in the palette, I always just used a variable, and show value. Just have the script set the actual value in the palette to be the same as the variable, and it should work okay, but it might not be exactly what you were thinking of.


Okay, illustration time!

I'd like a script that would allow you to change the value of a specific color using the up and down arrow keys. For example, in the screenshot here, all you'd have to do would be press Enter, then you'd just use left and right to switch between the R, G and B, and use up and down to increase and decrease (respectively) the selected color value.

I can script the cursor stuff, and maybe the color increasing/decreasing scripts, but I don't know how to use NPCs to display a specific value (like in a custom battle engine). Specifically a hexadecimal equivalent to a color's R/G/B value (00-FF).

For more details, http://rapidshare.de/files/33130170/ohrrpgce.rar.html has an RPG with the same custom menu I've been fiddling with. I want the NPCs to show up on the little colored blocks, but I don't know how to make them display the value I want.

I hope this is clear enough — I'm rather sleepy right now, g'night. X.x[/quote]
Back to top
View user's profile Send private message Yahoo Messenger
Gizmog1
Don't Lurk In The Bushes!




Joined: 05 Mar 2003
Posts: 2257
Location: Lurking In The Bushes!

PostPosted: Thu Sep 14, 2006 8:27 pm    Post subject: Reply with quote

Well, having it in hex complicates things. But, I think you could do it mathematically. It being hex, you could divide it by 16 to get the number for the "tens" place. If the number doesn't divide evenly into 16, you could subtract one until it DID divide into 16, and by keeping track of how many times you subtracted, you'd know what number to put into the "ones" column.

For example, you might have 128 Red, 56 green, and 0 blue.

128 divided by 16 is 8, so you'd have in hex 8 0, and your script could show that.

56 divided by 16 is 3.5, which isn't evenly divided. But the OHR automatically rounds down, so your script is going to think it's 3, which is 48. To fix that, have the script divide by 16, and then multiply that value by 16. If you don't get the same number you started with, you've got a problem. I'm not very good at Math, so I can't say for certain if either of these is always going to give you the correct figure, but you've got two possible solutions here. Solution A would be

Code:

56 / 16 = 3
16 * 3 = 48
48 != 56
56 - 1 = 55
Singles Variable: +1
55 / 16 = 3
16 * 3 = 48
48 != 55
55 - 1 = 54
Singles Variable: +1
...
48 / 16 = 3
16 * 3 = 48
48 = 48
Tens Variable = 3
Singles Variable = 8


That could take a while, and is rather unruly, but I think it'd always work. Alternately, you could try option b


Code:

56 / 16 = 3
16 * 3 = 48
Tens Variable = 3
48 != 56
56 - 48 = 8
Singles Variable = 8


That seems to do the same thing, only quicker, but I'm not good enough at Math to know if it'll always work.

For the last example, Green 0 your problem would be that if your script tries to divide by 0, it's going to go nuts. For that reason, you should make sure it checks first to be sure that the value ISN'T 0, and that it isn't less than 16.

After that, all you need to do is have it display the proper NPC for each gauge.

Somebody else probably knows a better and easier way than this.
Back to top
View user's profile Send private message Send e-mail AIM Address
Kizul Emeraldfire
Type: Cyber Dragoon




Joined: 26 Mar 2004
Posts: 229

PostPosted: Fri Sep 15, 2006 4:25 am    Post subject: Reply with quote

Moogle1 wrote:
You can do this with strings -or- store them in globals and use textboxes instead. If you need more than one set onscreen at a time, use strings.

Someone who has messed around with strings can probably tell you the exact syntax better than I can.


Wait, you can't use global variables in a string? O.o I would have to display more than one value at a time, so I'd probably have to use strings as an alternative to NPCs. I'm getting an idea for a script that would have 18 global variables and 36 NPCs to display it all (along with 4,608+lines of script to mess with it all. o.o At least, so says Calculator). I have no clue if it would work. I may try it though. :D

Gizmog1 wrote:
Well, having it in hex complicates things. But, I think you could do it mathematically. It being hex, you could divide it by 16 to get the number for the "tens" place. If the number doesn't divide evenly into 16, you could subtract one until it DID divide into 16, and by keeping track of how many times you subtracted, you'd know what number to put into the "ones" column.

For example, you might have 128 Red, 56 green, and 0 blue.

128 divided by 16 is 8, so you'd have in hex 8 0, and your script could show that.

56 divided by 16 is 3.5, which isn't evenly divided…

…For the last example, Green 0 your problem would be that if your script tries to divide by 0, it's going to go nuts. For that reason, you should make sure it checks first to be sure that the value ISN'T 0, and that it isn't less than 16.

After that, all you need to do is have it display the proper NPC for each gauge.

Somebody else probably knows a better and easier way than this.

(megasnipped for size) Heh, yeah that ÷0 thing would create a positive or negative infinity. XD
I suck at math, too. >.> I honestly have no real clue how to do this. XD
Back to top
View user's profile Send private message Yahoo Messenger
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Fri Sep 15, 2006 8:28 am    Post subject: Re: Question involving using NPCs to display a color value Reply with quote

Kizul Emeraldfire wrote:
How do I make NPCs to display a value (say, the amount of red in the 192nd color on the palette) at a certain X,Y spot on a map (like in a custom battle system)?

Or would I be able to do this with strings?

Also, would it be possible to write the values to global variables?


You want strings. The only reason to use NPC's for displaying numbers is if you are using a version older than rusalka (or if you happen to hate the default font and want a giant cartoony NPC-sized font ;)

Code:
show string at(ID, x, y)


Will position your string on the screen.

Code:

clear string(ID)
append number(ID, read color(192, color:red))


Will set you string to show the amount of red in master palette slot 192

And yes, you can use global variables here:

Code:
global variable(10, remember color)


Code:
remember color := read color(192, color:red)


Code:
append number(ID, remember color)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TwinHamster
♫ Furious souls, burn eternally! ♫




Joined: 07 Mar 2004
Posts: 1352

PostPosted: Fri Sep 15, 2006 9:23 am    Post subject: Reply with quote

Oh...My...goodness...
There are things as convenient as strings?

I'm still a little dazzled over it, but I think I got some parts of it down.

If I include:

Code:
$1 = "Lolzers"

show string (1)


into a script, it will simply display "Lolzers" at the top of the screen?

Good gosh! What else have I been missing out on?
Back to top
View user's profile Send private message Send e-mail AIM Address
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Fri Sep 15, 2006 1:13 pm    Post subject: Reply with quote

Close. The show string command shows the string at the bottom left of the screen, just like the show value command does with numbers.

The show string at and center string at commands are IMHO much more valuable. After you have used one of them to position your string on the screen, it will continue to display the live value of the string. You can make changes to the string, and they will be displayed at that spot automatically without further need for string showing commands. (see also hide string to make the string go away when you are done with it)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kizul Emeraldfire
Type: Cyber Dragoon




Joined: 26 Mar 2004
Posts: 229

PostPosted: Fri Sep 15, 2006 2:30 pm    Post subject: Re: Question involving using NPCs to display a color value Reply with quote

James Paige wrote:
Kizul Emeraldfire wrote:
How do I make NPCs to display a value (say, the amount of red in the 192nd color on the palette) at a certain X,Y spot on a map (like in a custom battle system)?

Or would I be able to do this with strings?

Also, would it be possible to write the values to global variables?


You want strings. The only reason to use NPC's for displaying numbers is if you are using a version older than rusalka (or if you happen to hate the default font and want a giant cartoony NPC-sized font ;)…


Woah. That sounds a lot simpler and easier than what I've been messing with (which is so large, it takes two HSS files and STILL won't compile right). I think I'll use this. :D

P.S.: is there any way to up the character limit in HSSED and HSPEAK? It only seems to support 65,536. :( Though it's possible to add more (only via editing it in a different text program such as Remotepad), HSPEAK only seems to compile 65,536 characters.

Edit: zapped for size.
Edit2: Say, just wondering — is there a way to set the color of a string? O.o
Edit3: Well, doesn't seem to matter — I can't get strings to work. I tried doing the stuff in 'What is a string and how do I use it?', but it didn't work — I keep getting the following when I try to compile:

Code:
ERROR: in line 514 of C:\D\ohrrpgce\script.hss
$1 = "The value of R will go here"
Expected top-level declaration but found $1="thevalueofrwillgohere"


So, um, what am I doing wrong in the below?

Code:
#=- For Hero Text Box Color -=#

$1 = "The value of R will go here"

show string at(1,200,32)
clear string (1)
append number(1, read color(34, color:red))


Can anyone tell me? >.>

Edit: oh yeah, I downloaded a nightly of HSPEAK, so I know that it isn't the problem.

Edit2: I also tried a newer PlotScr.hsd; I still get the error.
Back to top
View user's profile Send private message Yahoo Messenger
Kizul Emeraldfire
Type: Cyber Dragoon




Joined: 26 Mar 2004
Posts: 229

PostPosted: Sat Sep 16, 2006 12:35 pm    Post subject: Reply with quote

Okay, I figured out how to do it. 'Cept now it's saying that my global variables aren't being used. O_o

Edit: okay, fixed that — now it's just freezing up GAME. >_<
Edit2: OKAY, finally fixed it all — now I just need to figure one thing out: when I use the below code, why does the number always increment one if I press any key other than 'up' (after pressing up to change a color value), or decrement one if I press any key other than 'down' (after pressing it to change a color value)? For instance, I press up and set the red to 54, then I decide I want to add some blue, so I press left to get to the Blue selector — instead of jogging over to the Blue selector, it increases/decreases the red by 1. If I press it again, however, it does go to the Blue. But how do I keep it from doing this?

Code:
#=- For Hero Text Box Color -  Red (176,28) tag 15 -=#

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) #=- Show the current amount of red in color 50

if (check tag (15) == on) then (if (key is pressed (key:up)) then ( #=- If someone presses 'up', increase red
write color (50,color:red,read color (50,color:red)+1)))
update palette

if (check tag (15) == on) then (if (key is pressed (key:down)) then ( #=- If someone presses 'down', decrease red
write color (50,color:red,read color (50,color:red)--1)))
update palette

if (check tag (15) == on) then (if (key is pressed (key:right)) then ( #=- Go to Green
play sound (sfx:menu, false, true)
put hero(me,224,28)
set tag (15,off)
set tag (16,on)
wait (3)
))

if (check tag (15) == on) then (if (key is pressed (key:left)) then ( #=- Go to Blue
play sound (sfx:menu, false, true)
put hero(me,272,28)
set tag (15,off)
set tag (17,on)
wait (3)
))

#=- The others follow the same patern.

#=- For Hero Text Box Color -  Green (224,28) tag 16 -=#

remember HTBC-G := read color (50,color:green)
show string at (2,248,32)
string style (2,string:flat)
string color (2,41,0)
clear string (2)
append number (2,remember HTBC-G)

if (check tag (16) == on) then (if (key is pressed (key:up)) then (
write color (50,color:green,read color (50,color:green)+1)))
update palette

if (check tag (16) == on) then (if (key is pressed (key:down)) then (
write color (50,color:green,read color (50,color:green)--1)))
update palette

if (check tag (16) == on) then (if (key is pressed (key:right)) then (
play sound (sfx:menu, false, true)
put hero(me,272,28)
set tag (16,off)
set tag (17,on)
wait (3)
))

if (check tag (16) == on) then (if (key is pressed (key:left)) then (
play sound (sfx:menu, false, true)
put hero(me,176,28)
set tag (16,off)
set tag (15,on)
wait (3)
))



#=- For Hero Text Box Color -  Blue (272,28) tag 17 -=#

remember HTBC-B := read color (50,color:blue)
show string at (3,296,32)
string style (3,string:flat)
string color (3,24,0)
clear string (3)
append number (3,remember HTBC-B)

if (check tag (17) == on) then (if (key is pressed (key:up)) then (
write color (50,color:blue,read color (50,color:blue)+1)))
update palette

if (check tag (17) == on) then (if (key is pressed (key:down)) then (
write color (50,color:blue,read color (50,color:blue)--1)))
update palette

if (check tag (17) == on) then (if (key is pressed (key:right)) then (
play sound (sfx:menu, false, true)
put hero(me,176,28)
set tag (17,off)
set tag (15,on)
wait (3)
))

if (check tag (17) == on) then (if (key is pressed (key:left)) then (
play sound (sfx:menu, false, true)
put hero(me,224,28)
set tag (17,off)
set tag (16,on)
wait (3)
))

And one last thing — how do I make strings made with the 'show string at' command disappear? (P.S.: sorry for the rediculously long post. <.<)
Back to top
View user's profile Send private message Yahoo Messenger
msw188




Joined: 02 Jul 2003
Posts: 1041

PostPosted: Sun Sep 17, 2006 7:40 pm    Post subject: Reply with quote

I'm a little bit confused by this script. How is this script run? Is it a keypress script?

In any case, I think that the root of the problem lies in the fact that the string is written only at the beginning of each color section, not at the end. Say you are on RED, and you press up. In your code, the first thing to happen is that the screen displays the amount of RED (before changing it). Then it goes through your if checks and finds that you pressed up, so it increases the RED and updates the palette. But it does not update the string! This updated value only gets shown the next time a key is pressed. The immediate solution is to place string updating code AFTER all of the if checks. Then you would also want an 'initialization' script as well (that is to say, you want the strings to show the current values in the beginning before this keypress script here is ever run; maybe a map autorun script?).

There are other problems with this script. Let's say you are on RED and you press right. During the if checks for RED the tag 15 checks out, so the code is run turning tag 15 off and tag 16 on. But then the if checks for BLUE are run, and tag 16 is on so they are all run (and they may still be picking up the keypress right as well). I believe that this code could be cleaned up to be more efficient with the use of some local variables. Something like this:

Code:

variable(COLOR, OFFSET, STRG NUM, ON MENU, remember color)
suspend player
#initialize assuming you start on red
COLOR:=color:red
OFFSET :=0  #this will be an offset for the cursor and strings
STRG NUM:=1
ON MENU:= true
put hero(me, 176, 28) #the cursor, I presume
#show all the strings and set styles

#while loop which runs as long as they are looking at this menu
while(ON MENU == true),do
begin
wait for key

if(key up), then, (
write color (50, COLOR, read color(50, COLOR)+1)
)

if(key down), then, (
#same with --1
)

if(key right), then, (
OFFSET:= (OFFSET + 48, mod, 96)   #200->248, 176->224, etc
increment(STRG NUM)
if(STRG NUM == 4), then, (STRG NUM:=1) #cycle around
#sound effect
)

if(key left), then, (
#same with --48, decrement, and STRGNUM==0 -> STRGNUM:=3
)

update palette
if(OFFSET == 0), then, (COLOR:=color:red)
if(OFFSET == 48), then, (COLOR:=color:blue)
if(OFFSET == 96), then, (COLOR:=color:green)

put hero(me, 176 + OFFSET, 28)
remember color:=read color (50, COLOR)
clear string (STRG NUM)
append number (STRG NUM, remember color)
show string at (STRG NUM, 200 + OFFSET, 32)

if(key ESC), then, (ON MENU:=false)  #for leaving

end #end of while loop

resume player


Is this understandable? I haven't tested this, but I think that it should work better, use less tags, and be easier to troubleshoot since you can insert show value commands to see what the values of the variables are at any given time to help pinpoint any problems. Is it clear how the modular part works to allow the player to press right on the far end and end up on the left (and how this is being used simply as an offset for the position of the cursor and the string)? I can try to explain this more if you want.

Or, of course, you can stick to your method. I'm not sure what is causing your left/right problems that way, though.
Back to top
View user's profile Send private message Visit poster's website
Kizul Emeraldfire
Type: Cyber Dragoon




Joined: 26 Mar 2004
Posts: 229

PostPosted: Mon Sep 18, 2006 2:12 am    Post subject: Reply with quote

msw188 wrote:
I'm a little bit confused by this script. How is this script run? Is it a keypress script?

Oops, yeah it is. I guess I should've mentioned that. ^^;

msw188 wrote:
In any case, I think that the root of the problem lies in the fact that the string is written only at the beginning of each color section, not at the end. Say you are on RED, and you press up. In your code, the first thing to happen is that the screen displays the amount of RED (before changing it). Then it goes through your if checks and finds that you pressed up, so it increases the RED and updates the palette. But it does not update the string! This updated value only gets shown the next time a key is pressed. The immediate solution is to place string updating code AFTER all of the if checks. Then you would also want an 'initialization' script as well (that is to say, you want the strings to show the current values in the beginning before this keypress script here is ever run; maybe a map autorun script?).

You know what? That makes perfect sense! It's not updating 'til after I hit another key — thanks. I don't think I would've been able to figure that out this easy! XD

msw188 wrote:
There are other problems with this script. Let's say you are on RED and you press right. During the if checks for RED the tag 15 checks out, so the code is run turning tag 15 off and tag 16 on. But then the if checks for BLUE are run, and tag 16 is on so they are all run (and they may still be picking up the keypress right as well).

Actually, I just looked at it again — I think you mean 'you are on RED and you press left', not right — tag 16 is for Green, tag 17 is for Blue. Just thought I'd clear that up. ^_~ Although now that I think about it, you said that it was a problem. I don't know what would cause that, either. O.o Hmm… Odd…

msw188 wrote:
I believe that this code could be cleaned up to be more efficient with the use of some local variables. Something like this:

<Zapped for size.>

Is this understandable? I haven't tested this, but I think that it should work better, use less tags, and be easier to troubleshoot since you can insert show value commands to see what the values of the variables are at any given time to help pinpoint any problems. Is it clear how the modular part works to allow the player to press right on the far end and end up on the left (and how this is being used simply as an offset for the position of the cursor and the string)? I can try to explain this more if you want.

Or, of course, you can stick to your method. I'm not sure what is causing your left/right problems that way, though.


Actually, since I know what's causing the problem that I initially posted, it'd just be easier to to a few modifications to my method. I appreciate your script though — it could be of help to someone else sometime in the future (or me, if I happen to run out of space in my HSS and HSPEAK won't compile all of it! XD). :)

Edit: Yeah, that was definitely the problem — I just didn't have the string update after I modified something. Big thanks, msw188! :D

However, I still have one last problem to solve — how do I make the strings disappear? I tried using the Color String command to make them transparent (it didn't seem to work), and I even tried the Hide String command, in hopes that it would work (despite the documentation saying it wouldn't. XD). So how do I do this? >.>
Back to top
View user's profile Send private message Yahoo Messenger
msw188




Joined: 02 Jul 2003
Posts: 1041

PostPosted: Mon Sep 18, 2006 5:08 am    Post subject: Reply with quote

If hide string doesn't work, I can only think of two possible solutions, that are really just cheats. First is to clear the string. Then the string will still be on the screen, but since it has no characters nothing ought to be shown...?

Another possibility may be to reload the map. Do strings outlast map loads? I have not used strings outside of textboxes before. Or maybe you could position the string in some ungodly place where the player has no chance of ever seeing it. Not sure if your map even has such a place.

Is hide string broken? The string commands seem overly complicated. I think show no value is used to eliminate strings sometimes too, depending...

Oh yeah, the problem I was considering with left and right was basically this. You are on RED and you press right. Tag 15 is turned off and Tag 16 is turned on. However, then in the part of the code (GREEN) Tag 16 is checked and it is on, so I was afraid there was a chance that

if(checktag(16)==on), then, (if(key is pressed(key:right)), then...

would run, so tag 16 would be switched back off, and tag 17 would be switched on, and then the same thing would happen again in BLUE, until the computer decided that the key was no longer pressed. But it was only a guess; if you are not having any problems scrolling through, then I must have been mistaken.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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