Jump to content
  • 0

check if variable contains number


Question

Posted
while(input(.name$) == "" && (isdigit(.name$))){    input .name$;    }

I want the player to type only letters/words, if it contains any number he will have to type it again without numbers
how can I do that?

5 answers to this question

Recommended Posts

  • 0
Posted
prontera,150,150,6	script	Sample	112,{
	do {
		input .@string$;
	} while (callfunc("ValidateInput", .@string$));
	mes "You pick " + .@string$;
	close;
}

function	script	ValidateInput	{
	.@str$ = getarg(0, "");
	.@size = getstrlen(.@str$);
	for (.@i = 0; .@i < .@size; .@i++) {
		if (charat(.@str$, .@i) != " ") {
			if (!charisalpha(.@str$, .@i))
				return 1;
		}
	}
	return 0;
}

 

  • 0
Posted
9 hours ago, Patskie said:

prontera,150,150,6	script	Sample	112,{
	do {
		input .@string$;
	} while (callfunc("ValidateInput", .@string$));
	mes "You pick " + .@string$;
	close;
}

function	script	ValidateInput	{
	.@str$ = getarg(0, "");
	.@size = getstrlen(.@str$);
	for (.@i = 0; .@i < .@size; .@i++) {
		if (charat(.@str$, .@i) != " ") {
			if (!charisalpha(.@str$, .@i))
				return 1;
		}
	}
	return 0;
}

 

 

you are my savior!
can you explain your code for me? so that i can learn

how does the first part undestand that returning 1 or 0 must repeat the input or not

is this boolean? callfunc returns 1 or 0, while true it pass, false it fall into condition, that's right?

  • 0
Posted

The function i created will loop over each character of the string and check if that character is a letter or a number. If there is a number then always return 1 else 0.

You can return anything from a function you can leave it empty as well for any reason. I just use 0 and 1 because any !var means 0 and var means something else. 

  • 0
Posted
10 hours ago, Patskie said:

prontera,150,150,6	script	Sample	112,{
	do {
		input .@string$;
	} while (callfunc("ValidateInput", .@string$));
	mes "You pick " + .@string$;
	close;
}

function	script	ValidateInput	{
	.@str$ = getarg(0, "");
	.@size = getstrlen(.@str$);
	for (.@i = 0; .@i < .@size; .@i++) {
		if (charat(.@str$, .@i) != " ") {
			if (!charisalpha(.@str$, .@i))
				return 1;
		}
	}
	return 0;
}

 

how to prevent the player type only space?

Sem título.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...