Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Attempting to get a number out of a list item
- leBrenn
- Scratcher
12 posts
Attempting to get a number out of a list item
So I'm making a project where you type code in and then it's converted back into code Scratch can understand. Right now I'm trying to have it so you can take the number user input on the list, i.e “spriteX = 100” and then the sprite's X is set to 100. Anybody know how to do this? Thanks!
- helloworldbyeworld
- Scratcher
1000+ posts
Attempting to get a number out of a list item
Unfortunately, there is no block that can convert evaluate scratch code in text form, so you will need to make your own interpreter. So I'm making a project where you type code in and then it's converted back into code Scratch can understand. Right now I'm trying to have it so you can take the number user input on the list, i.e “spriteX = 100” and then the sprite's X is set to 100. Anybody know how to do this? Thanks!
For this specific command, I don't know what you mean by ‘the sprite’s X will be set to 100'. I'm assuming that you want the sprite's x position to be set to a number when this command is typed in. To do that, use an algorithm similar to this:
1. Remove all spaces from the command. This is to make processing easier.
2. If the command starts with 'spriteX=', continue. If not, check another command.
3. Split the command by '='.
4. Set the sprite's x position to the second part of the split result.
I hope this helped!
Helloworldbyeworld | 1200+ posts
Have a great day
- leBrenn
- Scratcher
12 posts
Attempting to get a number out of a list item
Unfortunately, there is no block that can convert evaluate scratch code in text form, so you will need to make your own interpreter. So I'm making a project where you type code in and then it's converted back into code Scratch can understand. Right now I'm trying to have it so you can take the number user input on the list, i.e “spriteX = 100” and then the sprite's X is set to 100. Anybody know how to do this? Thanks!
For this specific command, I don't know what you mean by ‘the sprite’s X will be set to 100'. I'm assuming that you want the sprite's x position to be set to a number when this command is typed in. To do that, use an algorithm similar to this:1. Remove all spaces from the command. This is to make processing easier.
2. If the command starts with 'spriteX=', continue. If not, check another command.
3. Split the command by '='.
4. Set the sprite's x position to the second part of the split result.
I hope this helped!
tysm! if anybody else needs help with a question like this, another thread i used to learn how to split a string is
https://scratch.mit.edu/discuss/topic/306639/?page=1#post-3177610
- Discussion Forums
- » Help with Scripts
- » Attempting to get a number out of a list item