AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   removing letter from begining of string (https://forums.alliedmods.net/showthread.php?t=84172)

whosyourdaddy 01-21-2009 21:27

removing letter from begining of string
 
lets say

szstring[32] = "I Love Apples"

how can i remove the first 2 characters in that string and make it become

szstring[32] = "Love Apples"

i know this is a poor examples i just need to learn how to remove the first to characters in a string

Drak 01-21-2009 21:43

Re: removing letter from begining of string
 
Code:
client_print(id,print_chat,"String: %s",szstring[0]);
Would actually print "Love Apples".

To remove it, I'm not positive but maybe.
Code:
 sztring[0] = "" // This might actually set the whole string to nothing or string[0] &= ""
or (probably not a good way)
Code:
format(sztring,31,"%s",szstring[0]);

Bugsy 01-21-2009 21:51

Re: removing letter from begining of string
 
Quote:

Originally Posted by whosyourdaddy (Post 747895)
lets say

szstring[32] = "I Love Apples"

how can i remove the first 2 characters in that string and make it become

szstring[32] = "Love Apples"

i know this is a poor examples i just need to learn how to remove the first to characters in a string

If you just want to return that portion of the string starting at Love, use szstring[2] instead of szstring.

to actually remove it from the string
format( szstring, 32, "%s" , szstring[2])

whosyourdaddy 01-21-2009 21:54

Re: removing letter from begining of string
 
ok now im using a for loop and all is there a way i can do a for loop and after every loop it will wait .5 seconds or something before doing another loop?

Bugsy 01-22-2009 00:01

Re: removing letter from begining of string
 
Quote:

Originally Posted by whosyourdaddy (Post 747906)
ok now im using a for loop and all is there a way i can do a for loop and after every loop it will wait .5 seconds or something before doing another loop?

No, but you can use a task with a variable as an index which can simulate a for-loop. The below code should simulate this for-loop.
PHP Code:

for( new iIndex START_VALiIndex<= END_VALiIndex++)
{
    
//your code
    
Pause 0.5


I have not tested it but something like below can simulate a for-loop with a timeout.

PHP Code:

new param[2];
param[0] = START_VAL;
param[1] = END_VAL;

set_task0.5 "YourCode" 5555 param "b"); 

PHP Code:

public YourCode(param[2])
{
    static 
iIndex;

    if( 
iIndex param[0] )
        
iIndex param[0];

    
// your code here

    
if( iIndex == param[1] )
        
remove_task5555 );
    else
        
iIndex++;



whosyourdaddy 01-22-2009 00:37

Re: removing letter from begining of string
 
Quote:

Originally Posted by Bugsy (Post 747940)
PHP Code:

for( new iIndex START_VALiIndex<= END_VALiIndex++)
{
    
//your code
    
Pause 0.5



so the pause 0.5 will work for sure in a for loop?

Bugsy 01-22-2009 00:44

Re: removing letter from begining of string
 
Quote:

Originally Posted by whosyourdaddy (Post 747946)
so the pause 0.5 will work for sure in a for loop?

No, I was giving you an example of what the code below that would simulate.

To start your for-loop, do this

PHP Code:

new param[2];
param[0] = START_VAL;
param[1] = END_VAL;

//This will start a 'loop' with 0.5 seconds between iterations.
set_task0.5 "YourCode" 5555 param "b"); 

Put your for-loop code in here:
PHP Code:

public YourCode(param[2])
{
    static 
iIndex;

    if( 
iIndex param[0] )
        
iIndex param[0];

    
// your for-loop code here

    
if( iIndex == param[1] )
        
remove_task5555 );
    else
        
iIndex++;



SchlumPF* 01-22-2009 01:34

Re: removing letter from begining of string
 
copy( some_new_variable, some_new_variables_len, szstring[2] )

Bugsy 01-22-2009 01:40

Re: removing letter from begining of string
 
Quote:

Originally Posted by whosyourdaddy (Post 747946)
so the pause 0.5 will work for sure in a for loop?

If you do not understand my code or what I am explaining, post what you have so far and what you are trying to do and I will try to write it for you.

whosyourdaddy 01-22-2009 02:15

Re: removing letter from begining of string
 
this is what i have and i hope u can make it so that every 5 seconds it will remove the first letter cause im limited to a certain amount of text in status text so i want it to be nice and smooth like its scrolling if needed u can remove 5 at a time what ever u prefer
Code:

new iLen = strlen( szString );
if(iLen > 60)
    while(iLen != i+1 )
    {
          if( gametime-LastMessage[id] > 0.5 )
          {
              if( iLen - 2 != i )
              {
                    format( szStringer, 256, "%s" , szString[i])
                    Create_StatusText( id, 0, szStringer);
              }
              else
                    Create_StatusText( id, 0, szString);

 
              LastMessage[id] = gametime;
              i++
          }
    }
else
    Create_StatusText( id, 0, szString);


didnt do any changes yet hoping u can do it for me thanks alot


All times are GMT -4. The time now is 01:41.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.