Raised This Month: $51 Target: $400
 12% 

Stuck at a part of code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 08-15-2011 , 19:48   Stuck at a part of code
Reply With Quote #1

Hey guys, I made a code of register_event("SayText",.... ) and for some wierd reason that I do not understand, it gets stuck in that WHILE sentence which is INSIDE the OTHER WHILE sentence, and not continuing any further.

Here's the code:

PHP Code:
public NoCurse()
{
    
client_print(0print_chat"its getting to the function")
    new 
message[300];
    new 
newmessage[300];
    
    
read_data(4message299)
    
client_print(0print_chat"message is: %s"message)
    
    new 
fast;
    
    while (
message[fast] != 0)
    {
        
client_print(0print_chat"Its in the while")
        new 
word[300]
        
        while ((
message[fast] != ' ') || (message[fast] != 0))
        {
            
word[fast] = message[fast++]
            
client_print(0print_chat"reading...")
        }

    }

Its printing all the client_prints but when it reaches to the while inside the while, then i get channel overflow cuz its type reading... too much times, for some reason it wont exit that while sentence. Why is that?

Last edited by Diegorkable; 08-15-2011 at 19:51.
Diegorkable is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-15-2011 , 20:27   Re: Stuck at a part of code
Reply With Quote #2

Those loops make no sense. What are you trying to do?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
APPLESAUCE
Junior Member
Join Date: Aug 2011
Old 08-15-2011 , 20:30   Re: Stuck at a part of code
Reply With Quote #3

Why are you looping a WHILE inside of a WHILE? And what the hell does this do?!

PHP Code:
while ((message[fast] != ' ') || (message[fast] != 0)) 
APPLESAUCE is offline
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 08-15-2011 , 20:40   Re: Stuck at a part of code
Reply With Quote #4

Well, it stops beacause, your telling it to ignore the case where the character is not a space, I jsut did a mental trace of your code, and it seems that if it cant get through the second while, it cannot increment, and if it cannot increment, the first while is stuck in the same stage, therefore the same stage forever.

EXAMPLE: the string "im baws", when it reaches the ' ' it will not go into the second while, therefore it wont do fast++ and it will always be stuck in the same damn step. Infinite loop.

try:
PHP Code:
    while (message[fast] != 0)
    {
        
client_print(0print_chat"Its in the while")
        new 
word[300]
        
        while ((
message[fast] != ' ') || (message[fast] != 0))
        {
            
word[fast] = message[fast]
            
client_print(0print_chat"reading...")
        }
    
fast++
    } 
I didnt say anything about the double while, I dont do it but let the man learn one step at a time. (you dont usually have a while inside of a while for a 1 dimensional array only for 2 dimensional arrays).
__________________
okay
ARES[ro] is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 18:28.


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