Jump to content
  • 0
oblinez

check if variable contains number

Question

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?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
prontera,150,150,6	script	Sample	112,{
	do {
		input [email protected]$;
	} while (callfunc("ValidateInput", [email protected]$));
	mes "You pick " + [email protected]$;
	close;
}

function	script	ValidateInput	{
	[email protected]$ = getarg(0, "");
	[email protected] = getstrlen([email protected]$);
	for ([email protected] = 0; [email protected] < [email protected]; [email protected]++) {
		if (charat([email protected]$, [email protected]) != " ") {
			if (!charisalpha([email protected]$, [email protected]))
				return 1;
		}
	}
	return 0;
}

 

Link to comment
Share on other sites

  • 0
9 hours ago, Patskie said:
prontera,150,150,6	script	Sample	112,{
	do {
		input [email protected]$;
	} while (callfunc("ValidateInput", [email protected]$));
	mes "You pick " + [email protected]$;
	close;
}

function	script	ValidateInput	{
	[email protected]$ = getarg(0, "");
	[email protected] = getstrlen([email protected]$);
	for ([email protected] = 0; [email protected] < [email protected]; [email protected]++) {
		if (charat([email protected]$, [email protected]) != " ") {
			if (!charisalpha([email protected]$, [email protected]))
				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?

Link to comment
Share on other sites

  • 0

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. 

Link to comment
Share on other sites

  • 0
10 hours ago, Patskie said:
prontera,150,150,6	script	Sample	112,{
	do {
		input [email protected]$;
	} while (callfunc("ValidateInput", [email protected]$));
	mes "You pick " + [email protected]$;
	close;
}

function	script	ValidateInput	{
	[email protected]$ = getarg(0, "");
	[email protected] = getstrlen([email protected]$);
	for ([email protected] = 0; [email protected] < [email protected]; [email protected]++) {
		if (charat([email protected]$, [email protected]) != " ") {
			if (!charisalpha([email protected]$, [email protected]))
				return 1;
		}
	}
	return 0;
}

 

how to prevent the player type only space?

Sem título.png

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.