Name Typ Von
Loop Me Not Definition AFRLme

Sie loopt mich, sie loopt mich nicht. Ein kleines Skript, das zeigt, wie du eine Funktion eine bestimmte Anzahl von Malen mit einer Pause zwischen den Durchläufen wiederholst. Das Skript setzt Visionaire Studio 5+ voraus.


Version 1: Wiederverwendbare Looping-Funktion

Diese Version kann mehrmals wiederverwendet werden, da wir eine Funktion aufrufen, die in einer Variablen gespeichert ist, die die Codezeilen enthält, die wir jedes Mal ausführen möchten, wenn die Funktion eine Schleife durchläuft.

Anweisungen

1. Füge dieses Skript im Skriptbereich des Editors von Visionaire Studio hinzu und lege es als Definitionsskript fest ...


--[[
Loop Me Not (reusable) [v1] (29/08/2022)
Written by AFRLme [Lee Clarke]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com
patreon: https://www.patreon.com/AFRLme
portfolio: https://afrl.me
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

function loopMeNot(act, inc, delay)
  if inc > 0 then
    act() -- execute code
    -- + --
    inc = inc - 1 -- decrement inc variable by 1
    setDelay(delay, function() loopMeNot(act, inc, delay) end) -- recall function after x delay
  end
end

2. Um das Skript zu nutzen, legst du irgendwo einen Aktionsteil Skript ausführen an und fügst etwa diesen Code ein ...


cf = function() -- lines of code we want to execute in the loop
  local n = math.random(10) -- generate random number up to a max value of 10
  print(n < 5 and "goodbye world!" or "hello world!") -- print "hello world!" if n >= 5, or "goodbye world!" if n < 5
end

loopMeNot(cf, 10, 1000) -- init loop, link action function, specfify loop amount & delay between loops in milliseconds


Version 2: Einweg-Looping-Funktion

Diese Version erfordert, dass für jeden Codezeilensatz, den du eine bestimmte Anzahl von Malen durchlaufen möchtest, eine neue Funktion geschrieben wird.

Anweisungen

1. Füge dieses Skript im Skriptbereich des Editors von Visionaire Studio hinzu und lege es als Definitionsskript fest ...


--[[
Loop Me Not (disposable) [v1] (29/08/2022)
Written by AFRLme [Lee Clarke]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com
patreon: https://www.patreon.com/AFRLme
portfolio: https://afrl.me
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

function loopMeNot(inc, delay)
  if inc > 0 then
    local n = math.random(10) -- generate random number up to a max value of 10
    print(n < 5 and "goodbye world!" or "hello world!") -- print "hello world!" if n >= 5, or "goodbye world!" if n < 5
    -- + --
    inc = inc - 1 -- decrement inc variable by 1
    setDelay(delay, function() loopMeNot(inc, delay) end) -- recall function after x delay
  end
end

2. Um das Skript zu nutzen, legst du irgendwo einen Aktionsteil Skript ausführen an und fügst etwa diesen Code ein ...


loopMeNot(10, 1000) -- init loop, specfify loop amount & delay between loops in milliseconds


Ressourcen

Name Beschreibung
N/A Für dieses Skriptbeispiel sind leider keine Versionen und Ressourcen verfügbar.