Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (howardR, 7th_zorro), 893 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Return Problem... #421739
04/24/13 15:06
04/24/13 15:06
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
Hi... (and sorry for my english)

I have created a function for checking a string with an array of strings
and i want to return the position of that string if exist ... otherwise return -1.

l_temp_1_array_str : contain the string.
g_commands_array : is a TEXT* that contain the strings that i want for check
g_commands_sum_int : is a variable that contain the sum of commands

l_temp_2_int : is the variable that i want to contain the position of string in array.

Code:
.
.
int l_temp_2_int = 0;
.
.
l_temp_2_int = f_check_str(l_temp_1_array_str);
wait_for(f_check_str);
.
.



Code:
typedef var bool;

//----------------------------------------
int f_check_str(STRING** l_temp_1_array_str)
{
   int l_i;
   bool l_while_stop_bool;
		
   l_i = 0; 
   l_while_stop_bool = false;	
   while ( (l_i < g_commands_sum_int) && (l_while_stop_bool == false) )
   {		
      if ( str_cmp(l_temp_1_array_str[0], (g_commands_array.pstring)[l_i] ) )
      {
         l_while_stop_bool = true;
      }
      else
      {
         l_i++;
      }
      wait(1);
   }

   if (l_while_stop_bool == true)
   {
      return l_i;
   }
   else
   {
      return -1;
   }
}



i have check inside that function and it works... and the l_i has the value that i want...

but the l_temp_2_int ( is the variable that call the int function ) takes a wrong number ... e.x.: (78775160)
(i have check this with the printf("%i", l_i); after the wait_for(f_check_str);

Please help...

thanks you all...

Best Regards.
Dimitris.


Last edited by NeoJT; 04/24/13 15:50.
Re: Return Problem... [Re: NeoJT] #421744
04/24/13 16:07
04/24/13 16:07
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
You can either use wait or return inside a function. Don't mix these two. When you call wait inside a function the calling function will procede in the next frame. In this case:
Code:
l_temp_2_int = f_check_str(l_temp_1_array_str);
wait_for(f_check_str);

l_temp_2_int will only get a value assigned if f_check_str returns a value in the exact frame it was called in. Otherwise the value will be random. On a quick look I don't see any reason why f_check_str should contain a wait. Does not make any sense to me.
Code:
typedef var bool;

Be careful. There already is a datatype BOOL and that's long. It does not make any sense to define a "bool" type for that function.


Always learn from history, to be sure you make the same mistakes again...
Re: Return Problem... [Re: Uhrwerk] #421754
04/24/13 17:55
04/24/13 17:55
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
i thought that inside all loops (except the "for" loop ) we must use wait();

i tried now and it works..

thank you Uhrweck...

and thank you for your explanation... i must check all my functions and all loops for that... :-)

Best Regards.
Dimitris.

Re: Return Problem... [Re: NeoJT] #421759
04/24/13 19:53
04/24/13 19:53
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Originally Posted By: NeoJT
i thought that inside all loops (except the "for" loop ) we must use wait();

You have to use wait when you want to wait a certain time or number of frames. wait does not have anything to do with loops in the first place. There are just many cases when a loop and wait go hand in hand, for example for continuously updating a certain property of an entity.


Always learn from history, to be sure you make the same mistakes again...
Re: Return Problem... [Re: Uhrwerk] #421760
04/24/13 20:22
04/24/13 20:22
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
in addition to what Uhrwerk said:

if you want to go through a while as fast as possible don't use any wait but make sure the while really exits properly. otherwise the application will freeze
...and user input don't work in that case (a mistake I made quite often)


POTATO-MAN saves the day! - Random
Re: Return Problem... [Re: Kartoffel] #421857
04/26/13 13:26
04/26/13 13:26
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
me 2 my friend... me 2...
i made that mistake and i thought that the wait() i must put inside
of all loops...

:-)

thank you all and for all :-)

( and sorry for my english ).

Best Regards.
Dimitris.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1