AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can't get a set_task to repeat/loop (https://forums.alliedmods.net/showthread.php?t=5854)

Trp. Jed 09-14-2004 21:26

Can't get a set_task to repeat/loop
 
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?

Da Bishop 09-14-2004 21:31

yeah let me see the code ur trying to repeat :?

Trp. Jed 09-14-2004 21:36

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.

Anpheus 09-14-2004 21:45

Use a global variable that goes up by 1 every time this_second executes. When it hits 20, execute this_third.

Da Bishop 09-14-2004 22:26

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) {
}


Johnny got his gun 09-15-2004 02:28

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.

Trp. Jed 09-15-2004 15:13

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! :)

Da Bishop 09-15-2004 15:24

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

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) {
}


Trp. Jed 09-15-2004 16:40

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?

Da Bishop 09-15-2004 17:21

im not following u...


All times are GMT -4. The time now is 17:18.

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