#More string problems

55 messages · Page 1 of 1 (latest)

burnt river
#

My suggestion would be to NOT use number at all, and just use keyboard_string for everything. The backspaces would automatically just work if you do that, without any need for extra code. For the string_digits part, you can do:

keyboard_string = string_digits(keyboard_string);

you would also just draw keyboard string and not number as well

upper estuary
#

@burnt riverThe error that it's giving me is coming from the Step eventif (string_length(keyboard_string) > 0){ if (string_width(keyboard_string)) < 40{ keyboard_string = ""; keyboard_string = string_digits(keyboard_string); }else{ keyboard_string = ""; } } circleWidth = real(keyboard_string) - 3;

#

unable to convert string "" to number
at gml_Object_obj_paintback_Step_0 (line 174) - circleWidth = real(keyboard_string) - 3;
############################################################################################
gml_Object_obj_paintback_Step_0 (line 174)

#

That line is just trying to get that value and subtract 3 from it so it knows the radius the circles should have that are being drawn.

burnt river
#

what is circlewidth for?

#

I see its to draw a circle but, not sure for what

upper estuary
# burnt river what is circlewidth for?

This is a light paint program. So the user is drawing a line essentially but wherever a line stops and it starts a new one there's a noticeable gap or crack so I fill that in with a circle.

burnt river
#

I see

#

so for anything requiring calculations, you do need number, since keyboard string can't be converted and will always be a string

upper estuary
#

first line of the two

burnt river
#

right, because keyboard_string can't be converted to anything not a string, like real

#

you would have to do:

number = keyboard_string;

first, before turning it into a real in calculations

upper estuary
#

ok

burnt river
#

you would be turning number into real

#

not keyboard string

upper estuary
#

okay now it says it can't convert it to a float.

burnt river
#

which one, whats the error

upper estuary
#

unable to convert string "" to float
at gml_Object_obj_paintback_Step_0 (line 175) - circleWidth = number - 3;
############################################################################################
gml_Object_obj_paintback_Step_0 (line 175)

burnt river
#

you forgot real

#

real(number)

upper estuary
#

unable to convert string "" to number
at gml_Object_obj_paintback_Step_0 (line 175) - circleWidth = real(number) - 3;
############################################################################################
gml_Object_obj_paintback_Step_0 (line 175)

#

Strings can be difficult.

burnt river
#

yep, you'd have to show me the rest of your code

upper estuary
#

Create:circleWidth = 2; number = 0;; keyboard_string = "2";

#

Step:if (string_length(keyboard_string) > 0){ if (string_width(keyboard_string)) < 40{ keyboard_string = ""; keyboard_string = string_digits(keyboard_string); }else{ keyboard_string = ""; } } number = keyboard_string; circleWidth = real(number) - 3;

#

Draw:```if (drawing){
surface_set_target(surf);
draw_set_color(global.color);

    draw_circle(oldX, oldY, circleWidth, false);
    draw_line_width(newX, newY, oldX, oldY, number);
    surface_reset_target();
    }```
burnt river
#

yea the conversion to real is whats messing things up here; usually when dealing with numbers, you grab it after pressing enter, not while you're entering keys

#

if you comment out the circle lines, does it run correctly?

burnt river
#

like circlewidth and draw_circle

#

and draw_line_width I guess since thats also real conversion

upper estuary
#

Yeah it's not putting anything into the input field.

burnt river
#

how are you drawing the input of keyboard string?

upper estuary
#

I'm not. I just run the program and see if it will let me input numbers

burnt river
#

so you're not drawing keyboard string at all? how do you know then if the input is working?

upper estuary
#

Yeah it won't let me draw because there's no number there.

burnt river
#

you should be able to draw it fine by just using:

draw_text(x,y,keyboard_string);
upper estuary
#

Yes I have that

#

draw_text(x + (sprite_width - 125), y + (windowMargin + 275), keyboard_string + cursor);

burnt river
#

thats what I was asking about

upper estuary
#

okay I was confused

burnt river
#

let me check something

#

@upper estuary okay, so I think the thing messing you up here is this line:

keyboard_string = "";
#

remove it and see what happens

#

make sure you're using real on the ones doing calculations

#

if keyboard string ends up blank, you'll get an error though

upper estuary
#

Yeah for some reason even though I'm setting it to 2 in the create event it's showing it as 0 in the field.

burnt river
#

this works for me 100%:

//create
number = 0;
keyboard_string = "2";

//step
number = real(string_digits(keyboard_string));
my_add = 500 + number + 60;

//draw
draw_text(100,100,my_add);
#

shows 562 correctly

#

and any digits entered

#

off to work now, but I'll check back later 👍

#

you can try this little code snippet in a blank project btw