oblinez Posted May 27, 2020 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 20 Reputation: 1 Joined: 02/23/14 Last Seen: May 27, 2023 Share Posted May 27, 2020 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? Quote Link to comment Share on other sites More sharing options...
0 Patskie Posted May 27, 2020 Group: Members Topic Count: 50 Topics Per Day: 0.01 Content Count: 1702 Reputation: 241 Joined: 09/05/12 Last Seen: 7 hours ago Share Posted May 27, 2020 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; } Quote Link to comment Share on other sites More sharing options...
0 oblinez Posted May 27, 2020 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 20 Reputation: 1 Joined: 02/23/14 Last Seen: May 27, 2023 Author Share Posted May 27, 2020 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? Quote Link to comment Share on other sites More sharing options...
0 Patskie Posted May 27, 2020 Group: Members Topic Count: 50 Topics Per Day: 0.01 Content Count: 1702 Reputation: 241 Joined: 09/05/12 Last Seen: 7 hours ago Share Posted May 27, 2020 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. Quote Link to comment Share on other sites More sharing options...
0 oblinez Posted May 27, 2020 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 20 Reputation: 1 Joined: 02/23/14 Last Seen: May 27, 2023 Author Share Posted May 27, 2020 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? Quote Link to comment Share on other sites More sharing options...
0 Patskie Posted May 28, 2020 Group: Members Topic Count: 50 Topics Per Day: 0.01 Content Count: 1702 Reputation: 241 Joined: 09/05/12 Last Seen: 7 hours ago Share Posted May 28, 2020 Comment //if (charat(.@str$, .@i) != " ") { if (!charisalpha(.@str$, .@i)) return 1;//} Quote Link to comment Share on other sites More sharing options...
Question
oblinez
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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.