Now you can extract letters/numerals in ChoiceScript

choicescript-updates
#21

I was playing around with this, and it looks like you can’t create a permanent variable for the first letter, only a temporary one. Is that true, or am I doing something wrong?

0 Likes

#22

I’m not 100% certain what you’re trying to do, but I’m guessing it’s something like:

*create name "J"
*input_text name
*create initial name#1

If I guessed that correctly you need to the start of the game, as *create is restricted to being the very first lines in your game (aside from other game setup commands). Any other commands disables the ability to use *create. (So what you should do is something like this):

*create name "Jessie"
*create initial "J"
*input_text name
*set initial name#1
2 Likes

#23

I keep encountering this error message when i try to run/compile:

line 7: Non-existent variable 'length'

But in the online IDE it works properly…

What i’m supposedly doing wrong?

*temp abc "abcd"
*temp map_x length(abc)

*comment there was a bug here "not located variable 'length'"! 



*temp last_letter abc#map_x

*label while

The word ${abc} is ${map_x}, and so its last letter is ${last_letter}.
0 Likes

#24

Is it possible to test if a letter or numeral is in the variable at all? Or would you just have to brute force it with a subroutine: “Is “b” the first letter? The second? The third? The fourth?”

0 Likes

#25

Seems like you’re maybe not using the latest version of ChoiceScript?

1 Like

#26

Brute force will be required. Try it like this.

*temp haystack "haystack"

*temp i 0
*label while
*set i+1
*if i <= length(haystack)
  *if (haystack#i) = "c"
    ${haystack} contains the letter "c" at position ${i}!
    *goto end
  *goto while
 ${haystack} doesn't contain the letter "c."
 *label end
0 Likes

#27

Thank you! Now I have a solution for the question I posed in “Holding multiple, testable values in one variable”. Well, I already had a solution, but it was a dire workaround that was harder to scale.

Here it is on my dropbox because it’s a bit too large for a forum post. It could be useful for an inventory system, or for creating summaries. Regardless of its use, it was fun to make.

1 Like

#28

I wrote up a cross-platform, customizable password system using this functionality, but I either failed to explain how to use it well enough, or I over looked a serious bug in the parsing code, so it didn’t really take off (especially since I haven’t had the time or motivation to take a closer look at it :stuck_out_tongue: ). The main concern I have for it in general though is that its really slow, even with only a handful of variables to save, it lags choicescript really bad, mostly due to the large number of loops that need to be done to make sure A) The password is a valid one (uses a checksum-like system) and B) Actually make sure the correct value is being put into the correct variable. My other issue with it is that it’s difficult to obfuscate the password without slowing things down even worse and doing hackish things. It would be nice to have the ability to convert to and from ASCII values.

0 Likes

#29

Thankyou!

That was the problem! when i downloaded the latest version it worked properly!

https://dl.dropboxusercontent.com/s/fm7wllt05fzwr7o/map_navigator.htm?dl=0

0 Likes

#30

If I wanted to use the extract characters ability to remove capitalization from the first letter of a variable, would I need a very long version of the example in post 26? And then reset all the capitals to lower case manually? Or is there an obvious easier solution that I’ve overlooked?

I have kind of an odd situation where I need to use the MC’s surname without a capital in just one specific instance. I’m pretty sure if I change the original variable, {surname}, to be lower case, I will consistently forget to list it as !{surname} because, habits.

0 Likes

#31

Natively I think the easiest solution would be to create a specific ${lowercase_surname} and brute force check every letter. So, not insanely long, probably about about a hundred lines give or take. Oh, and remember that some people have capitals in places other than the first letter of their name, so depending on what you’re using it for, you might want to check ever letter:

*temp name
*input_text name
*temp lowercase_name ""
*temp i 0
*label while
*set i +1
*if i <= length(name)
  *if ((name#i) = "A") or ((name#i) = "a")
    *set lowercase_name & "a"
    *goto while
  *elseif ((name#i) = "B") or ((name#i) = "b")
    *set lowercase_name & "b"
    *goto while
  *comment ... (You can finish it on your own).
  *else
    *comment non-roman alphabet character
    *set name &(name#i)
    *goto while
Your name: ${name} and wispered: ${lowercase_name}

That said, just adding transform to lower case isn’t too difficult if you want a more straightfoward solution:

  1. Open scene.js
  2. Fine this line: var replacer = /($(\!?\!?)\{)/; (at about line 153)
  3. Add a couple of extra exclamations to the replace (should look like this: /($(\!?\!?\!?\!?)\{)/;
  4. Find this piece of code:
    if (capitalize == "!") {
      value = value.charAt(0).toUpperCase() + value.slice(1);
    } else if (capitalize == "!!") {
      value = value.toUpperCase();
    }
  1. Add the following (overwriting that last line obviously, so everything is proper closed):
    } else if (capitalize == "!!!") {
      value = value.charAt(0).toLowerCase() + value.slice(1);
    } else if (capitalize == "!!!!") {
      value = value.toLowerCase();
    }
  1. ???
  2. Profit!

(But seriously, I don’t think I missed anything with that little addition, other than maybe error reporting somewhere I didn’t look for).

2 Likes

#32

Brilliant! That’s perfect; thanks so much. A practical solution AND a fun solution, what more could I ask?

0 Likes