Skip to content

Commit 3c13fbb

Browse files
another update
1 parent 6db684a commit 3c13fbb

17 files changed

Lines changed: 190 additions & 95 deletions

File tree

Code/ContextSystem/Contexts/Control/Loops/BreakKeyword.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class BreakKeyword : StandardContext, IKeywordContext
2424
2525
# for example:
2626
forever
27-
Wait 1s
27+
wait 1s
2828
2929
Print "attempting to leave forever loop"
3030
if {Chance 20%}

Code/ContextSystem/Contexts/Control/Loops/ForeverLoop.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using SER.Code.ContextSystem.Structures;
55
using SER.Code.Helpers.ResultSystem;
66
using SER.Code.MethodSystem.BaseMethods;
7-
using SER.Code.MethodSystem.Methods.WaitingMethods;
87
using SER.Code.Plugin;
98
using SER.Code.TokenSystem.Tokens;
109
using SER.Code.ValueSystem;
@@ -22,12 +21,12 @@ public class ForeverLoop : LoopContextWithSingleIterationVariable<NumberValue>,
2221
$$"""
2322
# {{Description}}
2423
# it can be interrupted only when the script is stopped, when "break" keyword is used, or the server restarts
25-
# it's VERY IMPORTANT to use yielding methods like "{{Method.GetFriendlyName(typeof(WaitMethod))}}"
24+
# it's VERY IMPORTANT to use yielding methods like "wait"
2625
# or else YOUR SERVER MAY CRASH!!!
2726
2827
# this will send an ad every 2 minutes
2928
forever
30-
Wait 2m
29+
wait 2m
3130
Broadcast * 10s "Join our discord server! {{MainPlugin.DiscordLink}}"
3231
end
3332
@@ -37,7 +36,7 @@ Wait 2m
3736
forever
3837
with $iter
3938
40-
Wait 1s
39+
wait 1s
4140
Print "current iteration: {$iter}"
4241
end
4342
""";

Code/ContextSystem/Contexts/Control/Loops/WhileLoop.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class WhileLoop : LoopContextWithSingleIterationVariable<NumberValue>
2424
"""
2525
# while loop repeats its body while the provided condition is met
2626
while {AmountOf @all} > 0
27-
Wait 1s
27+
wait 1s
2828
Print "there are players on the server!"
2929
end
3030
@@ -34,7 +34,7 @@ Wait 1s
3434
with $iter
3535
3636
Print "current attempt to leave loop: {$iter}"
37-
Wait 1s
37+
wait 1s
3838
end
3939
""";
4040

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using JetBrains.Annotations;
2+
using MEC;
3+
using SER.Code.ContextSystem.BaseContexts;
4+
using SER.Code.ContextSystem.Interfaces;
5+
using SER.Code.ContextSystem.Structures;
6+
using SER.Code.Exceptions;
7+
using SER.Code.Extensions;
8+
using SER.Code.Helpers.ResultSystem;
9+
using SER.Code.TokenSystem.Tokens;
10+
using SER.Code.TokenSystem.Tokens.Interfaces;
11+
using SER.Code.ValueSystem;
12+
13+
namespace SER.Code.ContextSystem.Contexts.Control;
14+
15+
[UsedImplicitly]
16+
public class WaitKeyword : YieldingContext, IKeywordContext
17+
{
18+
public virtual string KeywordName => "wait";
19+
20+
public virtual string Description => "Halts execution of the script for a specified amount of time.";
21+
22+
public virtual string[] Arguments => ["<duration>"];
23+
24+
public virtual string? Example =>
25+
"""
26+
# wait for 5 seconds
27+
wait 5s
28+
29+
# Waits using a variable
30+
$duration = 10s
31+
wait $duration
32+
""";
33+
34+
public override string FriendlyName => $"'{KeywordName}' keyword";
35+
36+
private IValueToken? _durationToken;
37+
private Func<TryGet<DurationValue>>? _getDuration;
38+
39+
public override TryAddTokenRes TryAddToken(BaseToken token)
40+
{
41+
if (token is IValueToken val && val.CapableOf<DurationValue>(out var get))
42+
{
43+
_durationToken = val;
44+
_getDuration = get;
45+
return TryAddTokenRes.End();
46+
}
47+
48+
return TryAddTokenRes.Error($"'{KeywordName}' keyword expects a duration value, but received {token.RawRep}.");
49+
}
50+
51+
public override Result VerifyCurrentState()
52+
{
53+
if (_durationToken == null)
54+
{
55+
return $"The duration was not provided for the '{KeywordName}' keyword.";
56+
}
57+
58+
return true;
59+
}
60+
61+
protected override IEnumerator<float> Execute()
62+
{
63+
var res = _getDuration!();
64+
if (res.HasErrored(out var error, out var duration))
65+
{
66+
throw new ScriptRuntimeError(this, error);
67+
}
68+
69+
yield return Timing.WaitForSeconds((float)duration.Value.TotalSeconds);
70+
}
71+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using JetBrains.Annotations;
2+
using MEC;
3+
using SER.Code.ContextSystem.BaseContexts;
4+
using SER.Code.ContextSystem.Interfaces;
5+
using SER.Code.ContextSystem.Structures;
6+
using SER.Code.Exceptions;
7+
using SER.Code.Extensions;
8+
using SER.Code.Helpers;
9+
using SER.Code.Helpers.ResultSystem;
10+
using SER.Code.TokenSystem.Tokens;
11+
12+
namespace SER.Code.ContextSystem.Contexts.Control;
13+
14+
[UsedImplicitly]
15+
public class WaitUntilKeyword : YieldingContext, IKeywordContext
16+
{
17+
public virtual string KeywordName => "wait_until";
18+
19+
public virtual string Description => "Halts execution of the script until a condition is met.";
20+
21+
public virtual string[] Arguments => ["<condition...>"];
22+
23+
public virtual string? Example =>
24+
"""
25+
# wait until there are no players on the server
26+
wait_until {AmountOf @all} is 0
27+
""";
28+
29+
public override string FriendlyName => $"'{KeywordName}' keyword";
30+
31+
protected readonly List<BaseToken> Tokens = [];
32+
private NumericExpressionReslover.CompiledExpression _expression;
33+
34+
public override TryAddTokenRes TryAddToken(BaseToken token)
35+
{
36+
Tokens.Add(token);
37+
return TryAddTokenRes.Continue();
38+
}
39+
40+
public override Result VerifyCurrentState()
41+
{
42+
if (Tokens.Count == 0)
43+
{
44+
return $"The condition was not provided for the '{KeywordName}' keyword.";
45+
}
46+
47+
if (NumericExpressionReslover.CompileExpression(Tokens.ToArray())
48+
.HasErrored(out var error, out var cond))
49+
{
50+
return error;
51+
}
52+
53+
_expression = cond;
54+
return true;
55+
}
56+
57+
protected override IEnumerator<float> Execute()
58+
{
59+
while (!GetConditionResult())
60+
{
61+
yield return Timing.WaitForOneFrame;
62+
}
63+
}
64+
65+
private bool GetConditionResult()
66+
{
67+
if (_expression.Evaluate().HasErrored(out var error, out var objResult))
68+
{
69+
throw new ScriptRuntimeError(this, error);
70+
}
71+
72+
if (objResult is not bool result)
73+
{
74+
throw new ScriptRuntimeError(
75+
this,
76+
$"'{KeywordName}' condition must evaluate to a boolean value, but received {objResult.FriendlyTypeName()}"
77+
);
78+
}
79+
80+
return result;
81+
}
82+
}

Code/Examples/BreachScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Cassie jingle "Containment breach detected . All heavy containment doors locked
1717
CloseDoor HeavyContainment
1818
LockDoor HeavyContainment
1919
20-
Wait 30s
20+
wait 30s
2121
2222
Cassie jingle "Lockdown lifted ." ""
2323
UnlockDoor HeavyContainment

Code/Examples/ChaosCoinScript.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ SetPlayerData @evPlayer "coin locked" true
7575
7676
repeat 5
7777
TransitionLightColor *room #ff0000ff .5s
78-
Wait .5s
78+
wait .5s
7979
TransitionLightColor *room #00ff00ff .5s
80-
Wait .5s
80+
wait .5s
8181
TransitionLightColor *room #0000ffff .5s
82-
Wait .5s
82+
wait .5s
8383
end
8484
85-
Wait .1s
85+
wait .1s
8686
UnlockDoor *room
8787
ResetLightColor *room
8888
@@ -99,7 +99,7 @@ SetPlayerData @evPlayer "coin locked" true
9999
100100
# waiting 15 seconds here
101101
repeat 15
102-
Wait 1s
102+
wait 1s
103103
104104
# every second we are checking if the role of the player changed
105105
# if so, we remove the countdown and unlock the coin
@@ -124,7 +124,7 @@ SetPlayerData @evPlayer "coin locked" true
124124
Bypass @evPlayer true
125125
126126
repeat 15
127-
Wait 1s
127+
wait 1s
128128
129129
if {@evPlayer -> role} isnt $initRole
130130
ClearCountdown @evPlayer
@@ -159,7 +159,7 @@ SetPlayerData @evPlayer "coin locked" true
159159
Cassie noJingle "pitch_0.7 warning . pitch_3 XMAS_JINGLEBELLS" ""
160160
Broadcast @evPlayer 5s "{$baseText}Most useful cassie message sent!"
161161
162-
Wait 7s
162+
wait 7s
163163
SetPlayerData @evPlayer "coin locked" false
164164
stop
165165
end

Code/Examples/DiscordServerInfoScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ run SetDiscordMessage
4747
4848
# update the message every 2 seconds
4949
forever
50-
Wait 2s
50+
wait 2s
5151
5252
run SetDiscordMessage
5353
EditDiscordMessage $url $messageId *msg

Code/Examples/DoorRestartScript.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class DoorRestartScript : Example
1313
Cassie jingle "ATTENTIONALLPERSONNEL . DOOR CONTROL CONSOLE MALFUNCTION DETECTED . INITIALIZING REACTIVATION SEQUENCE . ATTEMPTING FULL SYSTEM REACTIVATION IN . 3 . 2 . 1" "Attention all personnel. Door control console malfunction detected.<split>Initializing reactivation sequence. Attempting full system reactivation in..."
1414
1515
# wait for cassie to finish before restarting doors
16-
Wait 1s
17-
WaitUntil ({IsCassieSpeaking} is false)
16+
wait 1s
17+
wait_until {IsCassieSpeaking} is false
1818
1919
# restart effects
2020
LightsOut * 15s
@@ -27,7 +27,7 @@ Cassie noJingle "pitch_{RandomNum 0.15 0.25 real} .g{RandomNum 1 6 int}"
2727
end
2828
2929
# duration of the restart
30-
Wait 15s
30+
wait 15s
3131
3232
# revert to unlocked
3333
UnlockDoor *

Code/Examples/GnomingTimeScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class GnomingTimeScript : Example
3333
SetSize @plr {{@plr -> sizeX} - .1} {{@plr -> sizeY} - .1} {{@plr -> sizeZ} - .1}
3434
Hint @plr 5s "KILLED PLAYER - IT'S GNOMING TIME!"
3535
36-
Wait 15s
36+
wait 15s
3737
3838
# return them to normal
3939
SetSize @plr ({@plr -> sizeX} + .1) ({@plr -> sizeY} + .1) ({@plr -> sizeZ} + .1)

0 commit comments

Comments
 (0)