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

Joined: 26 Mar 2004 Posts: 229
|
Posted: Thu Feb 12, 2009 10:13 pm Post subject: Quick question involving Strings and (Global) Variables |
|
|
Is it possible to use the contents of a variable for a string without the string showing the variable's name?
For example, I have a script like:
Code: |
variable (hero dude)
hero dude := "Bob le Hamster"
$29 = "hero dude"
|
I haven't tested it yet, but this method (the only one I can think of) seems like it would only show the NAME of the variable (i.e. string 29 would show 'hero dude'), instead of the CONTENTS of the variable ('Bob le Hamster') like I would be wanting it to.
I'm feeling slightly sick at the moment, so I don't really have the patience to find a different way myself, but basically what I'm needing this for is a control configuration keypress script — it shows the different values for the different functions (confirm, cancel, left, right, etc.) in strings, and the player can move a cursor around on the configuration screen I've made and set the functions to whatever keys/buttons/axises they want, with the strings' values updating with the appropriate… whatever they pressed.
Basically, it does this:
- Display value for the currently assigned key/joystick button/axis
- If (key is pressed (key:ENTER)) then (get pressed key/button)
- Set customized value to <function>
- Display value for the currently assigned key/joystick button/axis
- If (key is pressed (key:ENTER)) then (get pressed key/button)
- Set customized value…
Lather, rinse, repeat. Probably over-complicated, but you get the idea? <.< >.>
Anyway, any help would be appreciated — thanks in advance.  |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Fri Feb 13, 2009 8:14 am Post subject: |
|
|
Right now it is impossible to store a string in a variable. (TMC is working on a plan to add that to a future version)
Anyway, for now, you can only assign strings to string ID numbers, like so:
Code: | $0="Bob le Hamster"
copy string(29, 0)
|
Of course, you can store a string ID number in a variable, so you may still be able to simulate the effect you want
Code: | variable(string ID)
$string ID="Bob le Hamster"
copy string(29, string ID)
|
Does that help? |
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Fri Feb 13, 2009 9:31 am Post subject: |
|
|
James Paige wrote: | Right now it is impossible to store a string in a variable. (TMC is working on a plan to add that to a future version)
Anyway, for now, you can only assign strings to string ID numbers, like so:
Code: | $0="Bob le Hamster"
copy string(29, 0)
|
Of course, you can store a string ID number in a variable, so you may still be able to simulate the effect you want
Code: | variable(string ID)
$string ID="Bob le Hamster"
copy string(29, string ID)
|
Does that help? |
Well… yes-and-no — what I'm wanting to do is show the value of a variable on the screen using a string — specifically something like:
Code: |
if (key is pressed (key:ENTER))
then (
show textbox (7) #=- This textbox will prompt the user to change the currently-assigned key, button or joystick axis to a the one of their choice (or hit Esc to cancel)
set tag (tag:Setting_Keys,on)
wait for key (any key)
Button A := get pressed key #=- Button A is a Global Variable, by the way. Get Pressed Key is a custom script that returns a custom-named value of whatever key/button/joystick axis is pressed.
$15 = "Button A"
set tag (tag:Setting_Keys,off)
)
|
Basically something sorta like that.
The only problem is, the string wouldn't show the VALUE of 'Button A', it would just show the words 'Button A'. I dunno how to get a string to show the value of a variable like I want it to. It only shows the variable's name. ¯\(º_O)/¯ Which makes sense, of course, but I still wish I could show the variable's value instead. XP |
|
Back to top |
|
 |
Spoon Weaver

Joined: 18 Nov 2008 Posts: 421 Location: @home
|
Posted: Fri Feb 13, 2009 10:41 am Post subject: |
|
|
have you tryed it without the quotes?
$15 := Button A |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Fri Feb 13, 2009 10:46 am Post subject: |
|
|
Edit: Oh look at all the people who beat me to posting while I took several hours to write this.
But you can't write hero dude := "Bob le Hamster"
The only variables which can contain strings are the 32 string variables. On the other hand, if hero dude contains a string handle, you can write this to copy it into another string:
Code: | variable (hero dude)
#a string handle - refer to a particular string
hero dude := 7
$hero dude = "Bob le Hamster"
29 $= hero dude
#that's short for "copy string(29, hero dude)"
|
If you want to add one string onto the end of another,
Code: | 29 $+ hero dude
#short for "concatenate strings(29, hero dude)" |
I imagine that what you want is something sort of like:
Code: | if (key is pressed(key:backspace)) then (
#use string 31 as a temporary string
$31="Backspace"
)
if (key is pressed(key:left shift)) then ( $31="Left Shift" )
...etc
#Now put the name in whichever string it needs to go in
current selection $= 31 |
_________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Fri Feb 13, 2009 11:32 am Post subject: |
|
|
You want append number
Quote: | append number (ID, number)
Appends the textual representation of number to the string with ID #ID. For example, append number(1,65) will append "65", not "A". |
_________________
|
|
Back to top |
|
 |
TwinHamster ♫ Furious souls, burn eternally! ♫

Joined: 07 Mar 2004 Posts: 1352
|
Posted: Fri Feb 13, 2009 11:37 am Post subject: |
|
|
Moogle1 wrote: | You want append number
Quote: | append number (ID, number)
Appends the textual representation of number to the string with ID #ID. For example, append number(1,65) will append "65", not "A". |
|
It looks like he wants the variables to hold characters, though.
...Which is what a string is supposed to do, so I don't quite understand why there are even variables to begin with. |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Fri Feb 13, 2009 11:51 am Post subject: |
|
|
Quote: | Well… yes-and-no — what I'm wanting to do is show the value of a variable on the screen using a string — specifically something like: |
That's not what he's saying here, though that's what his code seems to indicate. _________________
|
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Fri Feb 13, 2009 4:54 pm Post subject: |
|
|
Spoon Weaver wrote: | have you tryed it without the quotes?
$15 := Button A |
I tried to compile it, and Hamster Whisper gave me this:
"Unrecognised name $15. It has not been defined as script, constant, variable, or anything else" Was worth a try, though.
Moogle1 wrote: | Quote: | Well… yes-and-no — what I'm wanting to do is show the value of a variable on the screen using a string — specifically something like: |
That's not what he's saying here, though that's what his code seems to indicate. |
The 'value' of the variable being the name of a key. To use TMC's example:
The Mad Cacti wrote: | Code: | if (key is pressed(key:backspace)) then (
#use string 31 as a temporary string
$31="Backspace"
) |
|
Instead of using a zillion If/Thens to set the string (and appropriate tags and weirdness), I want to have something that detects the pressed key, sets one of eight Global Variables to contain the name of the pressed key (like Button A := BKSP (since 'Backspace' would overlap other strings and look rather messy)), and then dumps the value (BKSP) of the variable (Button A) into the string (in the example: $31), which would be shown with Show String At or Center String At.
TwinHamster wrote: | Moogle1 wrote: | You want append number
Quote: | append number (ID, number)
Appends the textual representation of number to the string with ID #ID. For example, append number(1,65) will append "65", not "A". |
|
It looks like he wants the variables to hold characters, though.
...Which is what a string is supposed to do, so I don't quite understand why there are even variables to begin with. |
Yes, I want the variables to hold characters. It would be silly (not to mention difficult to tell what the key was unless you knew the number for sure) to use the scancode numbers. \o.o/ It's easier to tell what a key/button is when it says (for example, something along the lines of) "BUTTON A: KEY X" instead of "BUTTON A: 46". At least in my opinion. >.>
Sorry if any of this post sounds rude — it wasn't intentional; I'm rather tired right now.  |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Fri Feb 13, 2009 8:28 pm Post subject: |
|
|
Kizul Emeraldfire wrote: |
Instead of using a zillion If/Thens to set the string (and appropriate tags and weirdness), I want to have something that detects the pressed key, sets one of eight Global Variables to contain the name of the pressed key (like Button A := BKSP (since 'Backspace' would overlap other strings and look rather messy)), and then dumps the value (BKSP) of the variable (Button A) into the string (in the example: $31), which would be shown with Show String At or Center String At. |
Like I said, Global variables can't hold strings as values! They can only hold a string handle, such as 31:
Code: | Button A := 31
$Button A = "BKSP" |
But this is probably not what you want. What you could do is this (see my first post):
1. Detect the pressed key, record its scancode and set string 31 to its name
2. Copy string 31 into the appropriate string, depending on which button is being set. Eg. Button A could be string 10.
Or, even better, you can pass the destination string as an argument to the script that checks for scancodes. EG:
Code: | script, get scancode and name, dest string, begin
if (key is pressed(key:backspace)) then (
$dest string = "BKSP"
return (key:backspace)
)
#etc...
end
...
wait for key
if (key is pressed(key:esc) == false) then (
Button A scancode := get scancode and name(10)
) |
_________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Calehay ...yeah. Class B Minstrel

Joined: 07 Jul 2004 Posts: 549
|
Posted: Fri Feb 13, 2009 8:33 pm Post subject: |
|
|
is not the proper format for putting values in the strings. You'd either have to use:
Code: | $15="stuff" #Makes string 15 return "stuff"
$15+"stuff" #Adds "stuff" to the end of string 15 |
The biggest problem with your plan is that you seem to assume that variables can hold ascii characters. They cannot. A variable can only hold a numerical value. You are never going to be able to put the value "BKSP" into a variable in Hamsterspeak (unless the magic variable plan is placed into motion.) What TMC suggested removes that problem.
Like this:
*Let's assume that strings 1-8 are shown on-screen, each holding the value of their respective buttons (Button A - 1, Button B - 2, etc.) We want to change Button A's value.
*We wait for a key press
*In sets of If-then statements like TMC wrote, you make string 31 equal a textual representation of that key. (So, if Backspace was pressed, then $31="BKSP")
*Then, we take string 31 and copy it's contents into string 1. The player then sees that Button A is now BKSP.
What this doesn't do is tell your program what these values are so that you will be able to use them as button presses in game. You are only going to be able to do that with scancodes.
Hopefully that made sense. _________________ Calehay |
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Sun Feb 15, 2009 4:42 pm Post subject: |
|
|
Hrm. Well, this certainly clears up a lot of problems I was having understanding how to use Strings. :o
Eh — I guess I'll just take the long-winded and possibly-horribly-over-complicated route and just use a bazillion If/Thens. :/
Thanks for the help, everyone, and also for the info about Strings and ideas on how to use 'em.  |
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Thu Feb 19, 2009 8:15 am Post subject: |
|
|
Well, I got something made here — and it WORKS… halfway.
http://www.mediafire.com/file/mtedyyqznnz/WIP.rar
It'll show the changed key name for whatever button you customized, but that's ALL it does. It doesn't make it to where that key is the one you have to press to do… whatever function it does.
By the way, the controls are:
* Arrow keys: move the cursor up/down; change things on the Options screen
* Enter/Return: confirm (only works on the 'OPTIONS', 'BACK' and 'MORE' menu items), customize keys
* Esc: exits the game (only on title), cancels customization (the function keys, various Locks, etc. also cancel it)
I've included all the scripts, the HSI and the RPG file in the linked RAR file. Hopefully someone can pinpoint what I'm doing wrong. \o.o/
The main scripts that I use are contained in 'Pressed Key Scripts.hss'; they're referenced by 'Options Screen 2 Keypress Script.hss' — 'BLiX.hss' is the main script file that includes all the other files. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Thu Feb 26, 2009 1:01 am Post subject: |
|
|
You didn't say what the problem was!! But I downloaded the file and noticed two problems:
-When you select 'RIGHT' pressing up doesn't select 'DOWN'
-You can't set the keys for UP, DOWN or RIGHT
But I guess you've probably fixed these by now? A very late reply. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Thu Feb 26, 2009 3:53 pm Post subject: |
|
|
The Mad Cacti wrote: | You didn't say what the problem was!! But I downloaded the file and noticed two problems:
-When you select 'RIGHT' pressing up doesn't select 'DOWN'
-You can't set the keys for UP, DOWN or RIGHT
But I guess you've probably fixed these by now? A very late reply. |
Hrm, I'll have to look into those. o.O I'm currently stuck with a shared computer, though, so it might be a while.
To explain what my problem is a little better: basically, after setting a button to a key (let's say, changing START to KB-U or something), the string showing the value of whatever button you changed is changed, however — pressing 'U' for 'Start' does nothing; it's still whatever it was before you tried to reconfigure it.
The string says it's different, but it isn't. :/ |
|
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
|