Yoko

All sides of Injection
It is currently 2025-12-02 09:08:39

All times are UTC+02:00




Post new topic  Reply to topic  [ 1 post ] 
Author Message
PostPosted: 2007-11-08 13:31:23 
Offline
Junior Expert
User avatar

Joined: 2004-06-24 22:08:56
Posts: 3220
Code:
Sub test()
   var id, i, str = ""
   if arg.getLastID() then
      id = arg.getLastID()
      for i = 0 to arg.Count( id )
         str = str + arg.Get( id, i ) + " "
      next
      arg.End( id )
   else
      str = "Test Message."
   endif
   uo.print( str )
endsub

sub main()
   uo.exec( "exec events" )
   event.setTimeout( "test", 1, "Test,Message,1" )
endsub

Sub events()
   repeat
      event.timeout.check()
      wait( 100 )
   until false
endsub

Sub event.timeout.ClearAll()
   uo.setGlobal( "e:t/o:close", "N/A" )
   uo.setGlobal( "e:t/o:queue", "N/A" )
endsub

Sub event.timeout.check()
   if uo.getGlobal( "e:t/o:close" ) == "N/A" || uo.timer() < val( uo.getGlobal( "e:t/o:close" ) ) then
      return false
   endif
   var evnt = explode( uo.getGlobal( "e:t/o:queue" ), ",", 0 )
   var id = "e:t/o:" + evnt
   arg.SetLastID( id )
   uo.exec( "exec " + explode( evnt, ":", 1 ) )
   repeat
      wait( 50 )
   until not arg.GetLastID()
   event.timeout.delF()
endsub

Sub event.timeout.delF()
   var queue = uo.getGlobal( "e:t/o:queue" )
   if queue == "" || queue == "N/A" then
      return false
   endif
   queue = right( queue, strlen( queue ) - strlen( explode( queue, ",", 0 ) ) - 1 )
   if not strlen( queue ) then
      uo.setGlobal( "e:t/o:close", "N/A" )
   else
      uo.setGlobal( "e:t/o:close", explode( queue, ":", 0 ) )
   endif
   uo.setGlobal( "e:t/o:queue", queue )
endsub

Sub event.setTimeout( func, timeout, argv )
   var q, i, queue_len, point = 0
   var run_time = uo.Timer() + timeout
   var id = "e:t/o:" + str( run_time ) + ":" + func
   var queue = uo.getGlobal( "e:t/o:queue" )
   if queue == "N/A" || queue == "" then
      queue = str( run_time ) + ":" + func + ","
   else
      queue_len = symCount( queue, "," )
      for i = 0 to queue_len -1
         q = explode( queue, ",", i )
         if val( explode( q, ":", 0 ) ) < run_time then
            point = point + strlen( q ) + 1
         else
            ; break
            i = queue_len -1
         endif
      next
      queue = left( queue, point ) + str( run_time ) + ":" + func + "," + right( queue, strlen( queue ) - point )
   endif
   uo.setGlobal( id, argv )
   uo.setGlobal( "e:t/o:queue", queue )
   uo.setGlobal( "e:t/o:close", explode( queue, ":", 0 ) )
endsub

Sub arg.Add( id, arg )
   var argv = uo.getGlobal( id )
   if argv == "N/A" then
      argv = ""
   endif
   uo.setGlobal( id, argv + arg + "," )
endsub

Sub arg.Get( id, num )
   return explode( uo.getGlobal( id ), ",", num )
endsub

Sub arg.Count( id )
   if id == "N/A" || id == "" then
      return 0
   endif
   return symCount( uo.getGlobal( id ), "," )
endsub

Sub arg.End( id )
   if uo.getGlobal( "e:arg:last" ) == id then
      uo.setGlobal( "e:arg:last", "N/A" )
   endif
   uo.setGlobal( id, "N/A" )
endsub

Sub arg.GetLastID()
   if uo.getGlobal( "e:arg:last" ) == "N/A" then
      return false
   else
      return uo.getGlobal( "e:arg:last" )
   endif
endsub

Sub arg.SetLastID( id )
   if uo.getGlobal( id ) == "" || uo.getGlobal( id ) == "N/A" then
      uo.setGlobal( "e:arg:last", "N/A" )
   else
      uo.setGlobal( "e:arg:last", id )
   endif
endsub

Sub getEntry( entry, str )
   var i
   for i=0 to strlen( str ) -strlen( entry )
      if MID( str, i, strlen( entry ) ) == entry then
         return i
      endif
   next
   return -1
endsub

Sub explode( string, pattern, num )
   var i, counter = 0, entry = 0
   for i = 0 to strlen( string ) - strlen( pattern )
      if MID( string, i, strlen( pattern ) ) == pattern then
         if counter == num then
            return MID( string, entry, i - entry )
         endif
         counter = counter + 1
         entry = i + strlen( pattern )
      endif
   next
   if counter == num && entry then
      return MID( string, entry, strlen( string ) - entry )
   endif
   return string
endsub

Sub symCount( string, pattern )
   var i, counter = 0
   for i = 0 to strlen( string ) - strlen( pattern )
      if MID( string, i, strlen( pattern ) ) == pattern then
         counter = counter + 1
      endif
   next
   return counter
endsub


Собственно сабж... Вытащил у себя из файлика events.sc.. Видать хотел сделать что-то серьёзное.

Насколько я могу вспомнить - планировалось использовать это для забывания чего-либо в больших количествах через некоторое время.....

_________________
YokoInjection CodeSweeper
Function not found?
Possession of mathematics at the level of art - a gift that is only available for election.
Sorry for my clumsy English.
Skype: d119060


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 1 post ] 

All times are UTC+02:00


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Limited