Jump to content


Photo

STRING TO REAL


  • Please log in to reply
8 replies to this topic

#1 gameside

gameside

    GMC Member

  • GMC Member
  • 70 posts

Posted 20 March 2012 - 04:36 PM

hi there!
is it possible to convert string value to real value like "123" to 123 i searched on google but cant find one the suit for my code here is the script i used for it


//Create Event
{
  input_active = false;
  input_limit = 6;
  input_cursor[0] = "";
  input_cursor[1] = "|";
  global.caph=500
}


//Any Key Event

{
  if (input_active = true) {
  if keyboard_check(vk_enter) { input_acive = false; }
  
  if (input_limit > 0) && (string_length(keyboard_string) > input_limit) {
  keyboard_string = string_copy(keyboard_string,1,input_limit)
  }
  global.caph = keyboard_string
  }
}


//Global Left Button Event

{
  active_instance = instance_position(mouse_x,mouse_y,obj_b_input_h)
  
  with (obj_b_input_h) { input_active = false }
  
  if (active_instance != noone) {
   with (active_instance) {
    keyboard_string = global.caph;
     input_active = true;
    }
  }
}
    


//Draw Event

{
  draw_sprite(sprite_index,input_active,x,y)
  draw_set_color(c_white)
  showtext = string_replace_all(global.caph,"#","\#")
  draw_text(x,y,showtext + input_cursor[input_active])
  draw_text(x,y-25,"Height")
}

i don't know what is the problem with the code :huh: can anyone make it correct for me PLEASE PLEASE PLEASE :blush:

Edited by gameside, 20 March 2012 - 05:08 PM.

  • 0

#2 chrscool8

chrscool8

    GMC Member

  • GMC Member
  • 1645 posts
  • Version:GM:Studio

Posted 20 March 2012 - 04:40 PM

real("123")

Done!
  • 0

#3 gameside

gameside

    GMC Member

  • GMC Member
  • 70 posts

Posted 20 March 2012 - 05:28 PM

real("123")

Done!

thanks chrscool8 but how? :wacko:
can you add this to my script HUH? :blink:
  • 0

#4 ParodyKnaveBob

ParodyKnaveBob

    theUndiscovered

  • GMC Member
  • 992 posts
  • Version:GM:Studio

Posted 21 March 2012 - 01:09 AM

Hello, gameside,

I'm going to make a request. It might sound snarky or facetious or whatever, but it's not. I mean it in all sincerity and depth. Please. Please, please please read the manual. (You're like the third or fourth person I've seen today asking a question that could've been solved by simply searching the manual for your keyword.) Read it once. Read it twice. Then when you have questions, go search it, too.

real(str) returns a real value. Therefore,

stuff = "123";
test = real(stuff);

means you'll now have two variables, stuff and test: stuff will contain the string value "123" whereas test will contain the real value 123.

However, I look at your code, and I can't help but wonder what this means:

keyboard_string = global.caph;

- you set global.caph to a real value of 500
- you're trying to set this real value to a variable meant for strings
- after doing a quick test, it appears that if you try to set anything to keyboard_string, it just resets keyboard_string anyway
- ...and that means that your line { keyboard_string = string_copy(keyboard_string,1,input_limit) } also does nothing for you

I hope you can rewrite your code better now... ~nodnod~ (...and please, please read the manual...)
  • 0

#5 gameside

gameside

    GMC Member

  • GMC Member
  • 70 posts

Posted 21 March 2012 - 06:28 AM

Hello, gameside,

I'm going to make a request. It might sound snarky or facetious or whatever, but it's not. I mean it in all sincerity and depth. Please. Please, please please read the manual. (You're like the third or fourth person I've seen today asking a question that could've been solved by simply searching the manual for your keyword.) Read it once. Read it twice. Then when you have questions, go search it, too.

real(str) returns a real value. Therefore,

stuff = "123";
test = real(stuff);

means you'll now have two variables, stuff and test: stuff will contain the string value "123" whereas test will contain the real value 123.

However, I look at your code, and I can't help but wonder what this means:

keyboard_string = global.caph;

- you set global.caph to a real value of 500
- you're trying to set this real value to a variable meant for strings
- after doing a quick test, it appears that if you try to set anything to keyboard_string, it just resets keyboard_string anyway
- ...and that means that your line { keyboard_string = string_copy(keyboard_string,1,input_limit) } also does nothing for you

I hope you can rewrite your code better now... ~nodnod~ (...and please, please read the manual...)


thanks ParodyKnaveBob, i know that real(string) convert the string in to real and string(val) will convert real to string. :sleep:
but my problem is that how to add this in above script . :wacko:
can any one make change to my script. so that when keyboard_check(vk_enter) the string value must convert to real value.

Edited by gameside, 21 March 2012 - 06:42 AM.

  • 0

#6 chrscool8

chrscool8

    GMC Member

  • GMC Member
  • 1645 posts
  • Version:GM:Studio

Posted 21 March 2012 - 11:49 AM

Before delving into that, I may as well ask, can you just go with the standard gm message box?

real(get_string(" ", " "))
or
get_integer(" ", 0)
  • 0

#7 gameside

gameside

    GMC Member

  • GMC Member
  • 70 posts

Posted 23 March 2012 - 05:33 AM

Before delving into that, I may as well ask, can you just go with the standard gm message box?

real(get_string(" ", " "))
or
get_integer(" ", 0)


i want that a user must enter value in the box that i made it in the game not in standard gm message box which is get_string(" ", " ")
or
get_integer(" ", 0).
is anyone can post edited script that can enter real value. :unsure:
  • 0

#8 ParodyKnaveBob

ParodyKnaveBob

    theUndiscovered

  • GMC Member
  • 992 posts
  • Version:GM:Studio

Posted 23 March 2012 - 06:17 AM

Are you looking for someone to tell you to try this?

keyboard_string = string(global.caph);

(I ask that because that's about the only place I can see you'd want anything like that -- and I already wrote that that won't work anyway.)

You said you don't know what's wrong. The thing is, neither do we. You didn't explain what's going right. You didn't explain what's going wrong. You didn't explain -how- it's going wrong. Did you write this script yourself, or grab it from somewhere else? If you wrote it yourself, it'd be good if you explained more to us. If you didn't write it, well, you still need to explain *something* or else we don't know what we're looking at necessarily.

Someone can point out a brick wall to me and say something's wrong with it. I can guess at the colors, the cracks in the mortar, the vines growing up it, etc., but if the other person never says "what's wrong is that it's smooth, but I ordered a more coarsely textured wall," then who knows if I'll ever wildly guess correctly or not. Please tell us what's right, what's wrong, and how it's wrong.

Regards,

Edited by ParodyKnaveBob, 23 March 2012 - 06:29 AM.

  • 0

#9 gameside

gameside

    GMC Member

  • GMC Member
  • 70 posts

Posted 24 March 2012 - 03:23 AM

Are you looking for someone to tell you to try this?

keyboard_string = string(global.caph);

(I ask that because that's about the only place I can see you'd want anything like that -- and I already wrote that that won't work anyway.)

You said you don't know what's wrong. The thing is, neither do we. You didn't explain what's going right. You didn't explain what's going wrong. You didn't explain -how- it's going wrong. Did you write this script yourself, or grab it from somewhere else? If you wrote it yourself, it'd be good if you explained more to us. If you didn't write it, well, you still need to explain *something* or else we don't know what we're looking at necessarily.

Someone can point out a brick wall to me and say something's wrong with it. I can guess at the colors, the cracks in the mortar, the vines growing up it, etc., but if the other person never says "what's wrong is that it's smooth, but I ordered a more coarsely textured wall," then who knows if I'll ever wildly guess correctly or not. Please tell us what's right, what's wrong, and how it's wrong.

Regards,


Ok I’m making a capture desktop tools using capture.xxl
and there would be to choice to 1.capture the whole desktop or to 2.capture a part of desktop [x, y, height, weight]
if you choose 1.capture the whole desktop it work great but the problem is if you chose a 2.part of desktop and when you want to enter the values in [x, y, height, weight]
Then it doesn’t work because the input boxes are string not real.
And i want that how to convert these string to real.
And i made four copy from above script and i just changed the verbals in four objects

global.capx=[ x-position]
global.capy= [y-position]
global.caph= [height]
global.capw=[weight]

i hop its clear now! :blush:

Edited by gameside, 24 March 2012 - 03:28 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users