Working with globals

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
Matokage
Slime Knight
Posts: 275
Joined: Sat May 26, 2012 11:48 pm
Contact:

Working with globals

Post by Matokage »

i'm trying to change the value of a global but it's not working.

Code: Select all

global variable (1,example)
scirpt,start,begin
example := 100
end
When I compile the Hspeak reaturns an erro message.

Code: Select all

example := 100
    ^
expected argument name, but found global variable example
What am I doing wrong?
"I can't buy food with glory"
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Hmm... I see a typo "scirpt" instead of "script"


Although I am not sure why it would cause that error message
User avatar
Matokage
Slime Knight
Posts: 275
Joined: Sat May 26, 2012 11:48 pm
Contact:

Post by Matokage »

found it, it was a typo, i was typing beign instead obegin
Last edited by Matokage on Wed Feb 18, 2015 1:37 pm, edited 1 time in total.
"I can't buy food with glory"
User avatar
Matokage
Slime Knight
Posts: 275
Joined: Sat May 26, 2012 11:48 pm
Contact:

Post by Matokage »

Now, does the "length" argument in the command globals to string (ID,starting global,length) the length of globals or the length of the string?
Last edited by Matokage on Wed Feb 18, 2015 1:59 pm, edited 1 time in total.
"I can't buy food with glory"
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

It's the number of globals to set.

That command isn't very useful anymore. Since it was added three things have changed:
1) There are 100 strings, so you can probably save a string to another one (with copystring) if needed
2) You can save strings in saved games (in nightly builds/Callipygous only)
3) You can store an unlimited number of strings in slices, which you can also save in saved games.
User avatar
Matokage
Slime Knight
Posts: 275
Joined: Sat May 26, 2012 11:48 pm
Contact:

Post by Matokage »

so, let me understand. Globals are basicaly obsolet, since you can save strings to slices and to saved games. but how do I Call those strings and it's values for a script?
"I can't buy food with glory"
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Matokage wrote:so, let me understand. Globals are basicaly obsolet, since you can save strings to slices and to saved games. but how do I Call those strings and it's values for a script?
Globals are still the best way to store numbers, but storing strings in globals is obsolete.

Go to "Edit General Game Data" -> "Saved Game Settings" and then turn on the "Save Strings" option.

Now any strings that you use with any of these commands: http://hamsterrepublic.com/ohrrpgce/doc ... 0Functions will be preserved in your save-games.
User avatar
Matokage
Slime Knight
Posts: 275
Joined: Sat May 26, 2012 11:48 pm
Contact:

Post by Matokage »

But, in this case a want a string from a global so i can add its value to a text slice.
"I can't buy food with glory"
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Matokage wrote:But, in this case a want a string from a global so i can add its value to a text slice.
You can copy strings to/from text slices using "set slice text" and "get slice text"

This has nothing to do with globals-- unless you mean that the string id is stored in a global, or that the slice handle is stored in a global, but that is not what "string to globals" means.

A string id is just a number, so you can store it in a single global variable, or a single local variable.

A slice handle is just a number, so you can store it in a single global variable, or a single local variable.

String to globals takes each letter of the string, converts it to an ascii number, and puts them into a series of different global variables one-after-another. There is no reason to bother with all that mess, it is just a throwback to the days before we had better ways to save strings in savegames.
User avatar
Matokage
Slime Knight
Posts: 275
Joined: Sat May 26, 2012 11:48 pm
Contact:

Post by Matokage »

But, i'm not using string to globals i'm using "Globals to string" so the global value is stored in a String and then i use that string for the text slice.

Getting more objective, i'm using some globals to store some status for the player

Code: Select all

global variable (1,AP)
global variable (2,APMAX)
the global AP is the current AP and the global APMAX is the maximum value to it so it can be changed later if needed

Code: Select all

variable (APmeter,APmeterMAX)
globals to string (1,1,3)
globals to string (2,2,3)
APmeter := create text
set slice text (APmeter,1)
put slice (APmeter,50,50)
APmeterMAX := create text
set slice text (APmeterMAX,2)
put slice (APmeterMAX,50,55)
And so i'm using a structure like this to show it's value on screen.
"I can't buy food with glory"
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Ah, I understand your problem a little better.

You do not want "globals to string" either. That command takes a bunch of global variables, looks insde them for ascii valuse, and then tries to construct a string out of them. That is definitely not what you want.

You have a number stored in a global variable, and you want to convert that number into a string.

Code: Select all

# Start with any number, stored in any kind of variable
num := 100

# clear a temporary string ID
$1=""

# convert the number into a string
append number(1, num)

# copy the temporary string into a string slice handle
set slice text(sl, 1)

Code: Select all

variable (APmeter,APmeterMAX)
APmeter := create text
$1=""
append number(1, AP)
set slice text (APmeter,1)
put slice (APmeter,50,50)
APmeterMAX := create text
$1=""
append number(1, APMAX)
set slice text (APmeterMAX,1)
put slice (APmeterMAX,50,55) 
Notice that I used string ID 1 for both the AP and the APMAX. that is because the string ID is only being used temporarily to hold the string just long enough to copy it into the text slice
User avatar
Matokage
Slime Knight
Posts: 275
Joined: Sat May 26, 2012 11:48 pm
Contact:

Post by Matokage »

Ahhh! That worked like a charm! thanks for the help.
"I can't buy food with glory"
Post Reply