SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 09/05/2011, 04:55 PM   #1
Unknown123
Guest
 
Posts: n/a
Default Function

Code:
if(IsValidText("Hi there")) return SendClientMessage(playerid, 0xFF0000FF, "Valid Text"); // Correct
if(IsValidText(":> Hello There")) return SendClientMessage(playerid, 0xFF0000FF, "Invailid Text"); // Correct
if(IsValidText("Hello :> There")) return SendClientMessage(playerid, 0xFF0000FF, "Vailid Text"); // Wrong
Code:
stock IsValidText(text[])
{
	for(new i = 0; i < sizeof(text[]); i++)
	{
	    if(text[i] == 'a' || text[i] == 'b' || text[i] == 'c' || text[i] == 'd'
		|| text[i] == 'e' || text[i] == 'f' || text[i] == 'g' || text[i] == 'h'
	 	|| text[i] == 'i' || text[i] == 'j' || text[i] == 'k' || text[i] == 'l'
		|| text[i] == 'm' || text[i] == 'n' || text[i] == 'o' || text[i] == 'p'
		|| text[i] == 'q' || text[i] == 'r' || text[i] == 's' || text[i] == 't'
		|| text[i] == 'u' || text[i] == 'v' || text[i] == 'w' || text[i] == 'x'
		|| text[i] == 'y' || text[i] == 'z')
		return 1;
	}
	return 0;
}
 
Old 09/05/2011, 05:05 PM   #2
Sascha
High-roller
 
Sascha's Avatar
 
Join Date: Jul 2009
Location: Germany
Posts: 1,387
Reputation: 64
Default Re: Function

for(new i = 0; i < sizeof(text); i++)

however I guess that's not the actual problem
__________________
FilterscriptsSgt's Driving License - Sgt's Debug - Sgt's RCON Addition - IpCheck - Advertisement
IncludesSgt's Vehicle Functions
FunctionsIsFloat
Searching for a team for a new server (Mapper/Admins/etc.).the website.
IP: 5.1.85.106

Sascha is offline  
Old 09/05/2011, 05:18 PM   #3
MadeMan
High-roller
 
MadeMan's Avatar
 
Join Date: Jun 2007
Posts: 3,467
Reputation: 237
Default Re: Function

Code:
stock IsValidText(text[])
{
    for(new i = 0; text[i]; i++)
    {
        if(text[i] != 'a' && text[i] != 'b' && text[i] != 'c' && text[i] != 'd'
        && text[i] != 'e' && text[i] != 'f' && text[i] != 'g' && text[i] != 'h'
        && text[i] != 'i' && text[i] != 'j' && text[i] != 'k' && text[i] != 'l'
        && text[i] != 'm' && text[i] != 'n' && text[i] != 'o' && text[i] != 'p'
        && text[i] != 'q' && text[i] != 'r' && text[i] != 's' && text[i] != 't'
        && text[i] != 'u' && text[i] != 'v' && text[i] != 'w' && text[i] != 'x'
        && text[i] != 'y' && text[i] != 'z')
        return 0;
    }
    return 1;
}
MadeMan is offline  
Old 09/05/2011, 05:19 PM   #4
Sascha
High-roller
 
Sascha's Avatar
 
Join Date: Jul 2009
Location: Germany
Posts: 1,387
Reputation: 64
Default Re: Function

won't that be an endless loop?
__________________
FilterscriptsSgt's Driving License - Sgt's Debug - Sgt's RCON Addition - IpCheck - Advertisement
IncludesSgt's Vehicle Functions
FunctionsIsFloat
Searching for a team for a new server (Mapper/Admins/etc.).the website.
IP: 5.1.85.106

Sascha is offline  
Old 09/05/2011, 05:25 PM   #5
Vince
Godfather
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 7,922
Reputation: 1948
Default Re: Function

Code:
stock IsValidText(const text[])
{
    for(new i = 0; i < sizeof(text); i++)
        if(!('A' <= text[i] <= 'Z') && !('a' <= text[i] <= 'z')) return 0;

    return 1;
}
ASCII table: http://www.asciitable.com/index/asciifull.gif
__________________

Won't reply to your topic if you use outdated methods (strtok, dini, non-threaded MySQL).
Vince is offline  
Old 09/05/2011, 05:30 PM   #6
Unknown123
Guest
 
Posts: n/a
Default Re: Function

Code:
indeterminate array size in "sizeof" expression (symbol "")

if i change
Code:
for(new i = 0; i < sizeof(text); i++)
to
Code:
for(new i = 0; i < sizeof(text[]); i++)
i will repove the warning but i will get save bug at my 1 post
 
Old 09/05/2011, 05:35 PM   #7
Vince
Godfather
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 7,922
Reputation: 1948
Default Re: Function

Sorry, this one should work. Tested it.

Code:
IsValidText(const text[])
{
    for(new i = 0, j = strlen(text); i < j; i++)
        if(!('A' <= text[i] <= 'Z') && !('a' <= text[i] <= 'z')) return 0;

    return 1;
}
__________________

Won't reply to your topic if you use outdated methods (strtok, dini, non-threaded MySQL).
Vince is offline  
Old 09/05/2011, 05:47 PM   #8
MadeMan
High-roller
 
MadeMan's Avatar
 
Join Date: Jun 2007
Posts: 3,467
Reputation: 237
Default Re: Function

Quote:
Originally Posted by Sascha View Post
won't that be an endless loop?
No, it will stop when reached to the end of the string.

Doing
Code:
for(new i = 0; text[i]; i++)
is same as
Code:
for(new i = 0; text[i] != 0; i++)
same as
Code:
for(new i = 0; text[i] != EOS; i++)
same as
Code:
for(new i = 0; text[i] != '\0'; i++)
MadeMan is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function just stops other function Blay09 Help Archive 2 01/01/2011 01:26 PM
function not working after another function [HLF]Southclaw Help Archive 5 03/05/2010 05:45 PM
Any function? deather Help Archive 1 14/03/2010 05:45 PM
[DUV]Function m0ta Português/Portuguese 2 06/01/2010 06:41 PM
C++ Function Danut Help Archive 5 19/04/2009 03:34 PM


All times are GMT. The time now is 09:09 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.