#would there ever be a use-case to use two different Events to make an "unreliable function"?

1 messages · Page 1 of 1 (latest)

safe aurora
#

my thinking is along the lines of this:

event1:Fire(message)
local timetowait = 30
local timewaited = 0
local reply
repeat
  task.wait(1)
  event2.Event:Connect(function(replymsg)
    reply=replymsg
    timewaited = 30
  end)
  timewaited+=1
until timewaited >= timetowait
if reply ~= nil then
  --stuff
else
  warn("nil reply")
end

that way the script doesn't wait endlessly if a function invoke falls through.

is this a reasonable idea, is it good for niche uses or is it better to just use Function instances?

and before somebody says that this takes too much space to use in every place instead of a function or whatever, consider:
module script that takes the inputs of the message, the outbound event and the inbound event that returns nil if it waited too long.

inner zinc
#

this is fixed of the script: local timetowait = 30
local timewaited = 0
local reply = nil

-- Create a single connection outside the loop
local connection
connection = event2.Event:Connect(function(replymsg)
reply = replymsg
timewaited = timetowait -- Force exit the loop on next check
if connection then
connection:Disconnect() -- Clean up the connection
connection = nil
end
end)

-- Wait for reply or timeout
repeat
task.wait(1)
timewaited += 1
until timewaited >= timetowait

-- Clean up connection if still exists (timeout case)
if connection then
connection:Disconnect()
end

-- Process the result
if reply ~= nil then
-- Do stuff with the reply
else
warn("No reply received within " .. timetowait .. " seconds")
end

unreal jacinthBOT
#

studio** You are now Level 2! **studio

inner zinc
#

local timeout = 30
local startTime = os.clock()
local reply = nil

local connection = event2.Event:Connect(function(replymsg)
reply = replymsg
end)

while os.clock() - startTime < timeout and reply == nil do
task.wait(0.1) -- Shorter wait for more responsive checking
end

connection:Disconnect()

if reply then
-- Proceed with reply
else
warn("Timeout waiting for reply")
end

safe aurora
#

that's... not what i asked

#

at all

#

i asked if it even made sense to do