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
pawn 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,266
Reputation: 57
Default Re: Function

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

however I guess that's not the actual problem
__________________
Filterscripts
Sgt's Driving License - Sgt's Debug - Sgt's RCON Addition - IpCheck - Advertisement
Includes
Sgt's Vehicle Functions
Functions
IsFloat

Trick to get faster and better help: Use (more or less) correct english and explain the problem detailed (and a "please" and "thank you" always helps).

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

pawn 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,266
Reputation: 57
Default Re: Function

won't that be an endless loop?
__________________
Filterscripts
Sgt's Driving License - Sgt's Debug - Sgt's RCON Addition - IpCheck - Advertisement
Includes
Sgt's Vehicle Functions
Functions
IsFloat

Trick to get faster and better help: Use (more or less) correct english and explain the problem detailed (and a "please" and "thank you" always helps).

check it out!
Sascha is offline  
Old 09/05/2011, 05:25 PM   #5
Vince
Godfather
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 6,645
Reputation: 1737
Default Re: Function

pawn 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
__________________

Vince is offline  
Old 09/05/2011, 05:30 PM   #6
Unknown123
Guest
 
Posts: n/a
Default Re: Function

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

if i change
pawn Code:
for(new i = 0; i < sizeof(text); i++)
to
pawn 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: 6,645
Reputation: 1737
Default Re: Function

Sorry, this one should work. Tested it.

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

Vince is offline  
Old 09/05/2011, 05:47 PM   #8
MadeMan
High-roller
 
MadeMan's Avatar
 
Join Date: Jun 2007
Posts: 3,472
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
pawn Code:
for(new i = 0; text[i]; i++)
is same as
pawn Code:
for(new i = 0; text[i] != 0; i++)
same as
pawn Code:
for(new i = 0; text[i] != EOS; i++)
same as
pawn 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 11:50 PM.


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