Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (AndrewAMD, TipmyPip), 12,420 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Timing issue #274321
06/26/09 13:56
06/26/09 13:56
Joined: Oct 2008
Posts: 67
C
Crypton Offline OP
Junior Member
Crypton  Offline OP
Junior Member
C

Joined: Oct 2008
Posts: 67
Damn I just bump into these things :P
Anyway I have timed this figure so it would blink images in a certain time: (btw this works fine, it's for a comparison to my faulty code)

Code:
function light_change()
{
   while(1)
   {
      //It also works whn I'd use If statements, but switch is something I don't use all the time and decided to do it here :P
      switch (active)
      { 
         case 0: //if active = 0
            if (p_tele_light.bmap == lgt_out) //Blink
            { 
            p_tele_light.bmap = lgt_red;
            }else{
            p_tele_light.bmap = lgt_out;
            }
         break;
         default: //basically if active = 1
            p_tele_light.bmap = lgt_active;
      }
   wait(-0.2); //Delay, which works!
   }
}

//this is called in main() like so:

function main()
{
   [...]
   level_load(""); // load an empty level
   wait(2);

   light_change(); //Working delay function!
   

   while(1) //that while loop
   { 
   [...] //Other stuff here... 
   }
}


So this works. But I tried to do delay similar to this and it won't work:

Code:
function shoot()
{
   while (mouse_left)
   {
      if ((gun[g_type][1] > 0)) 
      {
         [...]
      } 
   wait(-5); //Trying to delay that while, thus when holding mouse_left I'd get intervals for about 5 seconds...
   }
}



//In function main(). Well it's more difficult. If I'd place it next to my earlier light_change() it wouldn't work at all, I think it has something to do with "mouse_left detection". Engine won't update it because out of somekind update... :P

If I'd place it into main()'s "while loop", the delay won't give delay. It happens like it would be "while (1)".

Another might be that light_change() has "else statement" which makes the active variable check longer because when in 1.step "active = 0" and suddenly in that step "active = 1" then it takes one whole step to recheck that value to go into else.

I'm not sure which is the case. I have tested it in many ways.
How to work around it? How to get that delay with mouse_left == 1..

Hope I have given enough info...

LiteC Free btw.


New into Gamestudio and eager to learn it..
Stuff and games done in 2D: LINK
Re: Timing issue [Re: Crypton] #274344
06/26/09 15:14
06/26/09 15:14
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
you must call this function in a loop or add a loop to the function. From what you posted it is most probable that you are only calling the shoot function one time at the beginning of your program and that will just not work.

change your shoot function:
Code:
function shoot()
{
   while(1)
   {
      while (mouse_left)
      {
         if ((gun[g_type][1] > 0)) 
         {
            [...]
         } 
         wait(-5); // Trying to delay that while, thus when
                   // holding mouse_left I'd get intervals
                   // for about 5 seconds...
      }
   }
}




Our new web site:Westmarch Studios
Re: Timing issue [Re: Gordon] #274450
06/26/09 20:26
06/26/09 20:26
Joined: Oct 2008
Posts: 67
C
Crypton Offline OP
Junior Member
Crypton  Offline OP
Junior Member
C

Joined: Oct 2008
Posts: 67
yes, got it work now! Awesome laugh!

Anyway, so when
while(1)
{
while(mouse_left)
{
...

is in function and shoot() is in main() it works!
But when shoot() is without while(1) and is in main()'s while(1) then it won't work... funny :P. It should equal the same...


New into Gamestudio and eager to learn it..
Stuff and games done in 2D: LINK

Gamestudio download | 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