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

Can't get a set_task to repeat/loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Trp. Jed
Member
Join Date: Aug 2004
Old 09-14-2004 , 21:26   Can't get a set_task to repeat/loop
Reply With Quote #1

I'm having some problems getting a specific function to be called repeatedly. I've tried using the repear values and flags of set_task but AMX just gives me errors.

Basically what I want to do is this.

- set_task calls function A after 2 seconds.
- function A executes code every 0.5 seconds until 10 seconds have passed.
- function A then executes different code.

I tried making function A just contan two set_tasks, one at 0.5 to function B, and another at 10.0 for function C.

Function B executed once then stopped and then function C executed after 10 seconds. I think the fact it only executed once was because I used the same ID

Anyway, in short thats what I want to do, have one set of code execute every 0.5 seconds and then after 10 seconds from the time it was called, run another branch of code.

Anyone got any good suggestions?
Trp. Jed is offline
Da Bishop
Senior Member
Join Date: Aug 2004
Location: Chester County PA
Old 09-14-2004 , 21:31  
Reply With Quote #2

yeah let me see the code ur trying to repeat
Da Bishop is offline
Send a message via MSN to Da Bishop
Trp. Jed
Member
Join Date: Aug 2004
Old 09-14-2004 , 21:36  
Reply With Quote #3

Its a bit of a shambles at the moment so I'll do it as psuedo-code:

Code:
public this_first (id) {

   <execute this_second every 0.5 seconds for 10 seconds>
   <execute this_third after the above is complete>
}

public this_second (id) {
}

public this_third (id) {
}
Thats basically what I want to do without hanging up Half-Life. I tried using get_gametime() but it seemed to get stuck in a loop and crashed.

I need a friendly way to repeatedly execute this_second as stated above.
Trp. Jed is offline
Anpheus
Senior Member
Join Date: Aug 2004
Old 09-14-2004 , 21:45  
Reply With Quote #4

Use a global variable that goes up by 1 every time this_second executes. When it hits 20, execute this_third.
Anpheus is offline
Da Bishop
Senior Member
Join Date: Aug 2004
Location: Chester County PA
Old 09-14-2004 , 22:26  
Reply With Quote #5

Quote:
Originally Posted by Anpheus
Use a global variable that goes up by 1 every time this_second executes. When it hits 20, execute this_third.
yeah that works like something easy for example

Code:
new x

public this_first (id) { 

   <execute this_second every 0.5 seconds for 10 seconds> 
   <execute this_third after the above is complete> 
} 

public this_second (id) { 

x += 1
if (x = 20) {
set_task(0,"this_third")

} 

public this_third (id) { 
}
Da Bishop is offline
Send a message via MSN to Da Bishop
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 09-15-2004 , 02:28  
Reply With Quote #6

Now let's see, this should work.
Code:
/* Calls function on specified time. * Flags: * "a" - repeat. * "b" - loop task. * "c" - do task on time after a map timeleft. * "d" - do task on time before a map timelimit. */ native set_task(Float:time,const function[],id = 0,parameter[]="",len = 0,flags[]="", repeat = 0);

Code:
public firstfunction() {     log_amx("First function, gametime: %f", get_gametime())     set_task(0.5, "secondfunction", 0, "", 0, "a", 10)     set_task(5.0, "thirdfunction") } public secondfunction() {     log_amx("Second function, gametime: %f", get_gametime()) } public thirdfunction() {     log_amx("Third function, gametime: %f", get_gametime()) }

This gave the following output:
Quote:
L 09/15/2004 - 08:25:51: [variousstuff.amxx] First function, gametime: 1.000000

L 09/15/2004 - 08:25:52: [variousstuff.amxx] Second function, gametime: 1.800000

L 09/15/2004 - 08:25:52: [variousstuff.amxx] Second function, gametime: 2.050000

L 09/15/2004 - 08:25:52: [variousstuff.amxx] Second function, gametime: 2.596680

L 09/15/2004 - 08:25:53: [variousstuff.amxx] Second function, gametime: 3.034214

L 09/15/2004 - 08:25:53: [variousstuff.amxx] Second function, gametime: 3.581089

L 09/15/2004 - 08:25:54: [variousstuff.amxx] Second function, gametime: 4.019158

L 09/15/2004 - 08:25:54: [variousstuff.amxx] Second function, gametime: 4.565654

L 09/15/2004 - 08:25:55: [variousstuff.amxx] Second function, gametime: 5.003258

L 09/15/2004 - 08:25:55: [variousstuff.amxx] Second function, gametime: 5.550242

L 09/15/2004 - 08:25:56: [variousstuff.amxx] Second function, gametime: 6.096767

L 09/15/2004 - 08:25:56: [variousstuff.amxx] Third function, gametime: 6.096767
Well as you can see it does just about what you requested, although it doesn't execute the stuff exactly with 0.5 intervals, but I guess this'd depend on the speed of your system and other factors. At least the function comes in the right order, with the third function right after the last 2nd function as we expected.
Johnny got his gun is offline
Trp. Jed
Member
Join Date: Aug 2004
Old 09-15-2004 , 15:13  
Reply With Quote #7

Thanks for the input guys. I actually went along the lines of Da Bishop's post and as accurate timing isn't über important its good enough!
Trp. Jed is offline
Da Bishop
Senior Member
Join Date: Aug 2004
Location: Chester County PA
Old 09-15-2004 , 15:24  
Reply With Quote #8

well maybe i should add alittle to mine just to be sure there isn't much mistake on it

Code:
new x 

public this_first (id) { 

   <execute this_second every 0.5 seconds for 10 seconds> 
   <execute this_third after the above is complete> 
} 

public this_second (id) { 

x += 1 
if (x = 20) { 
set_task(0.5,"this_third") 
}else {
set_task(0.5,"this_second")

} 

public this_third (id) { 
}
Da Bishop is offline
Send a message via MSN to Da Bishop
Trp. Jed
Member
Join Date: Aug 2004
Old 09-15-2004 , 16:40  
Reply With Quote #9

Hey. The whole ID thing gets me though. I need to refine that a bit so I don't get collisions.

Just one thing though. If I set a task with one id and then start another with the same id, does the second cancel out the first?
Trp. Jed is offline
Da Bishop
Senior Member
Join Date: Aug 2004
Location: Chester County PA
Old 09-15-2004 , 17:21  
Reply With Quote #10

im not following u...
Da Bishop is offline
Send a message via MSN to Da Bishop
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:35.


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