Changing Text to a Number [Difficulty: đźź©]

Hey there fellow forumers!
It’s been a while since I’ve made a guide- I think the last one I made was my TD tug, and I’m pretty sure I posted that on my anniversary (June 5), so I’m glad to be back!
In reality, this guide should have been posted weeks ago, but I’m just writing it today and better late than never! I hope. Anyhow, I need to write this because I still need to write my series on block code and make chess and I eventually need to start ADOGAB. Anyhow, enough about me, it’s time to get to the guide!


Introduction

Hey there fellow creators! Anybody familiar with block code knows that there is a block to turn a number into a string, but what about the other way around?
This problem was posed by @pookiezach in the following post:

While one might reckon this to be impossible, we remember bh’s famous words and figure out how to do this little trick, a great precursor to my coding series! Let’s begin!


The System

Honestly, the system is near-impossible to create, but easy peasy to recreate! You just need to copy the following block code:


To clarify, var1 is basically your original text. This could be a string with a number somewhere in it, and that’s why I used the substring block to get the number I wanted. var2 is our output, obviously. And I changed it by 25 to prove it was a number, you can see for yourself that “25” + 25 returns 2525, but as you can see by my little celebration screenshot, var2 does become a number:

Now, obviously you don’t want to change your number, so you can just change it by -25 or changing it by 0 probably also works!


The Rationale (optional read)

So originally, bh had a different method to do this whole system, at once point once I which knew. But while I fail to remember the system, I do remember why his system works: variables in gkc do NOT like be text. Additionally, there’s a little bug in JS (which gimkit runs on) with new variables and multiplying text by numbers. So with this knowledge, I kinda just messed around and found out this way that essentially just confuses the system to let us do this!


What Difficulty Should This Guide Be?
  • 0/10 or :white_large_square:
  • 1/10 or :blue_square:
  • 2/10 or :green_square:
  • 3/10 or :green_square:
  • 4/10 or :yellow_square:
  • 5/10 or :yellow_square:
  • 6/10 or :orange_square:
  • 7/10 or :orange_square:
  • 8/10 or :red_square:
  • 9/10 or :red_square:
  • 10/10 or :purple_square:
  • 11/10 or :black_large_square:/:skull:
0 voters

As always, I am @Here_to_help, and Happy Gimkitting everybody!

11 Likes

1st like + 1st view :moai:


Bird makes the best guides.
W bird/hth [1]


  1. He’s also food, yummy bird ↩︎

6 Likes

Cool guide :fire:
W guide :ok_hand:

8 Likes

Peak guide birdie :))

8 Likes

I use a different setup to change text to numbers. What I do is create a property for every number, then I can get property x when x equals 4 or 9 or any other number.

Example of one of my properties.

6 Likes

Yeah but wouldn’t a ton of properties cost way more memory than this one thing of block code? Plus, there’s like a 128 property device limit, so wouldn’t you not be able to use all numbers? Or am I misunderstanding?

5 Likes

I only need 0-9 lol. It can go through one at a time.

5 Likes

Ohhhhh wait that’s so much smarter than what I did T-T Slim you need to make more guides you’re lowkey a genius and I overthink literally everything haha. The funny thing is I did the exact thing on code.org but didn’t think about doing that in gkc. Amazing!

5 Likes

This was what I was thinking when I originally saw the help post you mentioned.
Multi-digit numbers are harder, but still doable. You’d multiply each number in the substring by 10^ the index from the end of the substring - 1.
For decimals, you’d simply split off the decimal, and multiply by 10^-(distance from the start of the substring) + 1.

5 Likes

You can edit your guide to include my recommendation. I don’t mind. :slight_smile:

2 Likes

Well I still think I don’t understand it fully. Don’t you still need block code to run yours, because I don’t think you can split up the digits without it (and use like checkers or something). So aren’t you using block code and 10 properties? Or am I still misunderstanding?

1 Like