Skip to content

Commit 81df24f

Browse files
author
DEntisT
committed
repeat decorator parameter.
1 parent 77a3783 commit 81df24f

6 files changed

Lines changed: 76 additions & 8 deletions

File tree

doc/decorators.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void mytask() public;
4040

4141
# `this` keyword
4242

43-
- This keyword is used for modifying decorator argument values, without a specific order.
43+
- This keyword is used for modifying decorator parameter values, without a specific order.
4444

4545
```cpp
4646
@task;
@@ -61,4 +61,37 @@ void mytask() public;
6161
{
6262
console.println("Task works!");
6363
}
64-
```
64+
```
65+
66+
## `@task` parameters
67+
68+
### `interval` (integer)
69+
70+
- How much does it take till the timer is (re)called.
71+
72+
```cpp
73+
@task;
74+
this->interval=1000;
75+
void mytask() public;
76+
{
77+
console.println("Task works!");
78+
}
79+
```
80+
81+
**NOTE**: This parameter's default value is 0, so it is obligatory to set it before creating the task unless you want to rape your logs.
82+
83+
### `repeat` (boolean)
84+
85+
- Will the timer recall after being called once?
86+
87+
```cpp
88+
@task;
89+
this->interval=1000;
90+
this->repeat=false;
91+
void mytask() public;
92+
{
93+
console.println("Task works!");
94+
}
95+
```
96+
97+
**NOTE**: Now the timer will be called only once 1 second after `main` external-structured function gets called. Default value of this parameter is `true` so you don't need to set it unless you want to create a non-repeating timer.

scriptfiles/index.ps

132 Bytes
Binary file not shown.

src/modules/header.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ stock dpp_subexecute__3(const code[])
718718
////////////////////////////////////////////////
719719

720720

721-
stock dpp_createtask(const name[], interval)
721+
stock dpp_createtask(const name[], interval, repeat)
722722
{
723723
dpp_symbolcheck__(name);
724724
for(new i; i < dpp_maxtasks; i++)
@@ -729,6 +729,7 @@ stock dpp_createtask(const name[], interval)
729729
dpp_validtask[i] = 1;
730730
strmid(dpp_taskname[i], name, 0, 64, 64);
731731
dpp_interval[i] = interval;
732+
dpp_repeat[i] = repeat;
732733
return 1;
733734
}
734735
}

src/modules/interpreter.inc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,10 @@ stock dpp_process(line[])
815815
{
816816
if(!strcmp(tokengroup2[0], "void"))
817817
{
818-
dpp_createtask(arguments[0],dpp_interval__);
818+
dpp_createtask(arguments[0],dpp_interval__,dpp_repeat__);
819819
dpp_event = dpp_event_task;
820820
dpp_interval__=0;
821+
dpp_repeat__=1;
821822
}
822823
}
823824
dpp_lastdeco = dpp_deco_invalid;
@@ -1814,6 +1815,36 @@ stock dpp_process(line[])
18141815

18151816
dpp_interval__ = strval(thisargs[1]);
18161817
}
1818+
if(!strcmp(thisargs[0],"repeat"))
1819+
{
1820+
new i = 1;
1821+
dpp_removeslashes(thisargs[i]);
1822+
dpp_argclasscheck(thisargs[i]);
1823+
dpp_argoclasscheck(thisargs[i]);
1824+
dpp_argarraycheck(thisargs[i]);
1825+
dpp_argfunccheck(thisargs[i]);
1826+
dpp_argvarcheck(thisargs[i]);
1827+
dpp_argmathcheck(thisargs[i]);
1828+
dpp_argformargcheck(thisargs[i]);
1829+
dpp_argsystemval(thisargs[i]);
1830+
CallLocalFunction("dpp_arginstruct", "s", thisargs[i]);
1831+
CallLocalFunction("dpp_argenumcheck", "s", thisargs[i]);
1832+
CallLocalFunction("dpp_argtagcheck", "s", thisargs[i]);
1833+
1834+
dpp_formatarg(thisargs[i]);
1835+
1836+
new value=1;
1837+
if(!strcmp(thisargs[1],"true"))
1838+
{
1839+
value=1;
1840+
}
1841+
if(!strcmp(thisargs[1],"false"))
1842+
{
1843+
value=0;
1844+
}
1845+
1846+
dpp_repeat__ = value;
1847+
}
18171848
return 1;
18181849
}
18191850
return 1;

src/modules/tasks.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public dpp_taskinit()
2626
{
2727
if(dpp_validtask[i] == 1)
2828
{
29-
dpp_internaltasks[i] = SetTimerEx("dpp_runtask", dpp_interval[i], true, "i", i);
29+
dpp_internaltasks[i] = SetTimerEx("dpp_runtask", dpp_interval[i], bool:dpp_repeat[i], "i", i);
3030
}
3131
}
3232
return 1;

src/ps_mem.pwn

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ new dpp_validtask[dpp_maxtasks__];
290290
new dpp_taskname[dpp_maxtasks__][dpp_maxsymbolchar];
291291
new dpp_taskcodeblock[dpp_maxtasks__][dpp_buffersize];
292292
new dpp_interval[dpp_maxtasks__];
293+
new dpp_repeat[dpp_maxtasks__];
293294
//-----------------------------------------------------------
294295
//iterators
295296
new dpp_validiter[dpp_maxiter__];
@@ -458,7 +459,7 @@ new dpp_stkreg[DPP_STKSIZE][dpp_maxsymbolchar];
458459
new dpp_allowcollision;
459460
#define @emit__%0\32;%1\10;%3 dpp_asm__(%1);
460461
//-----------------------------------------------------------
461-
#define dpp_maxkwords 53
462+
#define dpp_maxkwords 54
462463
new dpp_kwords[dpp_maxkwords][256] = {
463464
"public",
464465
"inline",
@@ -512,7 +513,9 @@ new dpp_kwords[dpp_maxkwords][256] = {
512513
"true",
513514
"false",
514515
"this",
515-
"interval"
516+
"interval",
517+
"repeat"
516518
};
517519
//-----------------------------------------------------------
518-
new dpp_interval__;
520+
new dpp_interval__;
521+
new dpp_repeat__=1;

0 commit comments

Comments
 (0)