Jump to content
The forums will be going offline for an extended maintenance period at 1400hrs GMT on 19th June 2025. The number of hours for this downtime is intentionally not advertised due to the nature of these upgrades. ×
  • 0

check if variable contains number


oblinez

Question


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  20
  • Reputation:   1
  • Joined:  02/23/14
  • Last Seen:  

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

  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   241
  • Joined:  09/05/12
  • Last Seen:  

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;
}

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  20
  • Reputation:   1
  • Joined:  02/23/14
  • Last Seen:  

  On 5/27/2020 at 10:38 AM, 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;
}

 

Expand  

 

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

  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   241
  • Joined:  09/05/12
  • Last Seen:  

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

  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  20
  • Reputation:   1
  • Joined:  02/23/14
  • Last Seen:  

  On 5/27/2020 at 10:38 AM, 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;
}

 

Expand  

how to prevent the player type only space?

Sem título.png

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   241
  • Joined:  09/05/12
  • Last Seen:  

Comment 

//if (charat(.@str$, .@i) != " ") {
    if (!charisalpha(.@str$, .@i))
        return 1;
//}

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...