Gamestudio Links
Zorro Links
Newest Posts
freewhyblogelsewhere
by 9489cpjf. 06/03/24 06:06
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,075 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19056 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 | 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