Post Reply 
Emu48--can I programmatically construct a 'NAME'?
12-23-2022, 04:56 AM
Post: #1
Emu48--can I programmatically construct a 'NAME'?
I want to let my program construct global names under Emu48/HP48GX. Here is the use case: character generation for a role-playing game. The game provides a number of skills with (human) defaults, and each sapient species alters this list: dwarves know nothing of Boating but are adept with Mineral Lore, for example.
So I want the stack to be
2: {list-of-adjustments}
1: 'SPECIES-CODE'
and the program DO$ADJ will handle the overwriting/merging of the list, first making a copy of the defaults (SP$SKB) and assigning it to, say, 'DW$SKB' for dwarves, which name I want to construct in-program. Simply concatenating 'DW' and '$SKB'gives 'DW+$SKB', which isn't what I want given my naming conventions. I suppose I could just join 'DW' and 'SKB' yielding 'DW+SKB', but is there a way to get the name I want?

Charles? He was my grandfather. --Oh, *that* Charles. We share a common ancestor.
Find all posts by this user
Quote this message in a reply
12-23-2022, 11:37 AM (This post was last modified: 12-23-2022 11:39 AM by DavidM.)
Post: #2
RE: Emu48--can I programmatically construct a 'NAME'?
(12-23-2022 04:56 AM)rickster Wrote:  I suppose I could just join 'DW' and 'SKB' yielding 'DW+SKB', but is there a way to get the name I want?

Assuming you've already gotten the pieces ("DW" and "$SKB") as strings on the stack, the following would create the global name I think you are referring to:
Code:
  +                     @ concatenates "DW" and "$SKB"
  "'" SWAP OVER + +     @ encapsulates within single quotes
  STR→                  @ converts the resulting string to global name

This will leave the global name 'DW$SKB' on the stack. If you want to execute DW$SKB instead of leaving its ID on the stack, just omit the second line in the code above (the one commented as "encapsulates within single quotes").
Find all posts by this user
Quote this message in a reply
12-27-2022, 01:21 AM
Post: #3
RE: Emu48--can I programmatically construct a 'NAME'?
Or, with "AB" and "CD" :

Just add the two STRINGS, with +, to get "ABCD";
then execute OBJ—>, to change the string into the new variable name 'ABCD'.

Gil
Find all posts by this user
Quote this message in a reply
12-27-2022, 04:38 AM
Post: #4
RE: Emu48--can I programmatically construct a 'NAME'?
(12-27-2022 01:21 AM)Gil Wrote:  Or, with "AB" and "CD" :

Just add the two STRINGS, with +, to get "ABCD";
then execute OBJ—>, to change the string into the new variable name 'ABCD'.

Note that this only works if there's no object named ABCD in the current path hierarchy. If there is, it will be executed instead of having the name placed on the stack (which I believe is what rickster needs here).

Placing the single quotes around the string insures that the name is placed on the stack instead of executing the object if it already exists.

Also, STR→ and OBJ→ do exactly the same thing when given a string as the argument (they literally call the same internal routine). There's no difference between them in this situation.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)