The Daily Click ::. Forums ::. Klik Coding Help ::. Converting Strings to values
 

Post Reply  Post Oekaki 
 

Posted By Message

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
7th October, 2009 at 08:52:13 -

for some reason when I use the Val() command, the number just comes out to 0. I've done plenty of tests and that seems to be the problem. However, if I convert a number to a string then back to a number again, it works perfectly fine. There are no specific conditions for triggering this problem, it seems to happen no matter what I do. Specifically I'm using an edit box and when it comes time for the frame change, it copies that edit box and converts that string to a value that can be put into a numbers array and be ready to be converted back to a string when the time calls for it.

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

~Matt Esch~

Stone Goose

Registered
  30/12/2006
Points
  870

VIP Member
7th October, 2009 at 09:37:44 -

I am assumign Val() takes the ASCII value of a single character. You can't just convert a string to a number, I am not sure how you would define it. If you give a valid ASCII number you should be able to convert it to a character, and then evidently you can convert that back to a number. You would have to iterate over the string's characters one by one and place the Val(char) in an integer array. Though maybe you are saying that the Val( ) of a single character returns 0?

 
http://create-games.com/project.asp?id=1875 Image


Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1968

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
7th October, 2009 at 09:40:01 -

I don't know what you're doing but it works fine for me.
If it's an edit box, why don't you use the "get numeric value" expression instead of using val()?

 
n/a

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
7th October, 2009 at 10:42:31 -

Hay, chloe.
Try using a string array instead of number array... im using it and it works quite much better... since you can much more easily convert numbers to string both ways than strings to numbers.
By the way if you still need some gfx let me know.


 
Code me a sausage!

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
7th October, 2009 at 17:35:32 -

@ esch
Yeah, that would make sense, but as it is, single characters (no matter what they are) always return a value of 0. I have a test field set up with 1 string and 1 counter and trying different combinations there. Single characters don't work, words don't work, ect.

@sketchy
no dice, that doesn't work either. Maybe my MMF is broke?

@don
I might just have to do that. thanks for the offer for gfx, but i think the project is over for now.

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1968

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
7th October, 2009 at 18:05:21 -

Are you saying that even something like this doesn't work?

* Always
-> Set Counter to Edit Value( "Edit Box" )

What exactly does you source look like?
Maybe try the "rich edit object" instead?


 
n/a

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
7th October, 2009 at 20:45:01 -

that's basically it. it's either that or set counter to Val(string/editbox/"whatever") something like that. It doesn't matter where the text comes from, the problem is for whatever reason I can't get text to be converted to a value.

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
7th October, 2009 at 21:10:00 -

I think your problem is that you are trying to do the wrong thing.
The "convert text to number" function is a bit misleading in its label; it does not actually convert all text to a value, instead what it does is it pulls a number out of an ascii string, and returns that. For example, the text:

val("hello world 1928")
returns the value 1928. The "hello world " string is simply discarded

I don't remember exactly what happens if you have multiple substrings of numbers in there, like "293 hi 304"
But the point is that it does NOT convert the string into its hex-->decimal byte code representation or anything like that. If you want a string of the ascii code for each character, something like "abc" = 001002003 (those aren't the actual values in ascii), then you'd need to use uh I think theres an ASCII object, or maybe the binary object.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
7th October, 2009 at 21:16:14 -

that makes perfect sense now! I did a quick test to confirm it visually, and when converting a number into a string, it doesn't actually convert the numbers to letters, it actually just makes a string of the exact same numbers, which also explains why it's possible to convert the opposite direction. I'll fiddle with some more extentions and see if it might not be less work to just convert all my values to a string array. thanks a bunch pixelthief!

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49610

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
7th October, 2009 at 21:51:29 -

String Parser can do this.

 
n/a

nim



Registered
  17/05/2002
Points
  7232
8th October, 2009 at 00:25:59 -

Are you trying to get the ascii value for the string? Like, A=65, B=66, etc?
The string parser's asc() function can do this (as UrbanMonk said) For example:

asc( "String Parser", "A")

Edited by nim

 
//

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
8th October, 2009 at 04:19:35 -

Bah, all of that warrents alot of unnessessary code, I find it would be much easier to convert my number array to a text array and re-write all the code, it will work out a lot better in the long run for what I'm doing, imo. thanks alot guys for all of your help!

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49610

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
8th October, 2009 at 04:54:42 -

Ha ha! What? All of that just to try and put strings in where numbers are supposed to go?

Yeah it would definitely be better to just convert the array. You'll be glad you did later.

 
n/a

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
8th October, 2009 at 08:16:34 -

well, id like to have all the data used during the game to be in one array that deletes itself at the end of the game, rather than several arrays strewn about througout the game. im not a big fan of huge arrays, but i have it compacted into 5 different catagories on the z axis, the x axis for longevity and the y for constant variables. it's just the dang strings givin me a big issue.

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
8th October, 2009 at 15:05:56 -

would anyone by any chance know if there is a command somewhere to erase all the spaces from a string?

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
8th October, 2009 at 20:04:28 -

Use backspace! kidding..
Erase spaces from what strings array?

 
Code me a sausage!

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
8th October, 2009 at 21:23:04 -

just from a specific string that I call. for instance
Johnston Wallace The Good Guy (?) would become
JohnstonWallaceTheGoodGuy

using the string parser, and the URL prep line deal thing I can get it to replace the spaces with +'s, but that's no good for what I'm trying to accomplish.

Edited by Chloe Sagal

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49610

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
8th October, 2009 at 21:31:53 -

Add the string that you want to remove spaces from to the string parser then do this:

remove$( "String Parser", " ")

To get a string without them.

 
n/a

Chloe Sagal

under the influence of FUN

Registered
  19/02/2009
Points
  607

Orange
8th October, 2009 at 22:20:33 -

kick ass. you're on the ball U.M.

 
Patreon: http://www.patreon.com/chloesagal
Twitter: https://twitter.com/ChloeSagal

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49610

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
9th October, 2009 at 00:52:54 -

I have the String Parser object in all of my projects even if I don't use it!

It's functionality should really be built into mmf.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click