Harbynger
|
  |
| Joined: 06 Jul 2008 |
| Total Posts: 34677 |
|
|
| 13 Feb 2017 10:10 PM |
Hey, so I'm having trouble with this. I absolutely **hate** high level languages and **vastly** prefer C/C++ where this isn't a prob#em.
Anyway, tl;dr being, what do you do when wait() doesn't exist on the game engine (ie, Elder Scrolls Online addon)?
Here's my code: -- Interesting stuff...
local Addon = { name, inCombat, --Starting this out by reading the tutorial... haha, what a mess I'm making. };
Addon.name = "[REDACTED]" -- https://www.youtube.com/watch?v=M-d8had4C00&t=1m38s
----------------------------------------------------------------------------- -- Boilerplate Lua... -- Hey, I'm from ROBLOX, so expect my Lua to be god-awful and nightmarish to read. Lua is a bad language anyway :P -- Here's our hack to get the 'connect line' back...
local AddonManager = {}; function AddonManager:connect(f) EVENT_MANAGER:RegisterForEvent(Addon.name, EVENT_ADD_ON_LOADED, f); end
function AddonManager:disconnect() EVENT_MANAGER:UnregisterForEvent(Addon.name, EVENT_ADD_ON_LOADED); end
local CombatManager = {}; function CombatManager:connect(f) EVENT_MANAGER:RegisterForEvent(Addon.name, EVENT_PLAYER_COMBAT_STATE, f); end
function warn(string) d(string) end
function wait(time) -- Crashes the client... local init = GetSecondsSinceMidnight(); repeat until GetSecondsSinceMidnight() > init + time; end
----------------------------------------------------------------------------- local timer = 0; local tldgui; -- Make us our thing... local lblcntr;
function OnPlayerCombatState(event, inCombat) if (inCombat ~=##ddon.inCombat) then Addon.inCombat = inCombat; tl####################nCombat); end if (inCombat) then warn("Entering Combat..."); while (inCombat) do timer = timer + 1; if (timer > 0) then lblCounter:SetText("Counter: " .. timer); else lblCounter:SetText("Entering Combat!"); end wait(1); --???? Why is this crash? end else wa#############ombat..."); timer = 0; end end
function Addon:CreateGui() -- Don't worry about this. end
function Addon:Init() Addon:CreateGui(); tl####################### Addon.inCombat = IsUnitInCombat("player"); CombatManager:connect(OnPlayerCombatState); AddonManager:disconnect(); end
AddonManager:connect(Addon.Init);
harbynger@roblox:~$ sudo rm -rf / --no-preserve-root && echo "Get slam jammed, kid!" |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
| |
|
Harbynger
|
  |
| Joined: 06 Jul 2008 |
| Total Posts: 34677 |
|
|
| 13 Feb 2017 10:44 PM |
| ? harbynger@roblox:~$ #### rm -rf / --no-preserve-root ## echo "Get slam jammed, kid!" |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
| |
|
|
| 14 Feb 2017 01:11 AM |
| Don't be cruel to # heart that's true. |
|
|
| Report Abuse |
|
|
|
| 14 Feb 2017 01:12 AM |
| I'm glad ROBLOX is finally taking action to counter swearing. I've grown sick of bad words like "a" and "then" on this platform. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
| |
|
|
| 14 Feb 2017 01:19 AM |
| maybe the interns are on strike and purposely sabotaged the filter? as far as i know they only hire one actual programmer so this is good explanation |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 14 Feb 2017 01:27 AM |
They said that they were doing something with the filter that would make it total garbage for a while. Who knows why
|
|
|
| Report Abuse |
|
|
Harbynger
|
  |
| Joined: 06 Jul 2008 |
| Total Posts: 34677 |
|
|
| 14 Feb 2017 06:28 PM |
Haha. I absolutely **hate** it too. Though, I think there's a future in deep learning, this is **not** the way to do it. Yeah I'll appear nicer than my brother who has no problem outright calling them satanic and whatever too, ugh, it's awful.
Though, on the platform I'm writing this Lua code for, sleep() also isn't a part of the standard. There's no actual waiting function.
All I have is GetTimeSinceMidnight() (which is in milliseconds), and that's it. So I can compare two times. I don't know how to block the thread from executing without crashing the Lua VM and thus the client.
harbynger@roblox:~$ sudo rm -rf / --no-preserve-root && echo "Get slam jammed, kid!" |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 14 Feb 2017 06:50 PM |
Is it not just as simple as one of these?
lua-users(dot org)/wiki/SleepFunction
|
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 14 Feb 2017 06:56 PM |
| Is there some sort of "update" event? |
|
|
| Report Abuse |
|
|
pydlv
|
  |
| Joined: 01 Apr 2011 |
| Total Posts: 5891 |
|
|
| 14 Feb 2017 07:06 PM |
| c++ is a high-level language |
|
|
| Report Abuse |
|
|
Harbynger
|
  |
| Joined: 06 Jul 2008 |
| Total Posts: 34677 |
|
|
| 14 Feb 2017 07:23 PM |
os.sleep isn't available.
There is an update event, but it calls for every frame, and tends to severely hamper performance using it for anything other than logging the c-- I'm going to get yelled at for using it, but I'll try that. Thanks.
harbynger@roblox:~$ sudo rm -rf / --no-preserve-root && echo "Get slam jammed, kid!" |
|
|
| Report Abuse |
|
|
Harbynger
|
  |
| Joined: 06 Jul 2008 |
| Total Posts: 34677 |
|
|
| 14 Feb 2017 08:44 PM |
I'd have to make a mess if it's to be exactly 1 second and not based on the frames per second.
Plus there's no way to know the actual FPS.... so that's wonderful.
harbynger@roblox:~$ sudo rm -rf / --no-preserve-root && echo "Get slam jammed, kid!" |
|
|
| Report Abuse |
|
|
Harbynger
|
  |
| Joined: 06 Jul 2008 |
| Total Posts: 34677 |
|
|
| 14 Feb 2017 08:48 PM |
'c++ is a high-level language'
Not as high-level as like Lua, Python, and Java.
harbynger@roblox:~$ sudo rm -rf / --no-preserve-root && echo "Get slam jammed, kid!" |
|
|
| Report Abuse |
|
|
Harbynger
|
  |
| Joined: 06 Jul 2008 |
| Total Posts: 34677 |
|
|
| 14 Feb 2017 08:58 PM |
function sleep(n) -- seconds local t0 = GetSecondsSinceMidnight(); while GetSecondsSinceMidnight() - t0 <= n do end -- Crash! end
harbynger@roblox:~$ sudo rm -rf / --no-preserve-root && echo "Get slam jammed, kid!" |
|
|
| Report Abuse |
|
|
Harbynger
|
  |
| Joined: 06 Jul 2008 |
| Total Posts: 34677 |
|
|
| 14 Feb 2017 09:03 PM |
Can I do this with a coroutine or something? I don't know how to do that.
ugh, why can't ZeniMax implement the whole Lua VM/language and not some weird part of it.
harbynger@roblox:~$ sudo rm -rf / --no-preserve-root && echo "Get slam jammed, kid!" |
|
|
| Report Abuse |
|
|
Harbynger
|
  |
| Joined: 06 Jul 2008 |
| Total Posts: 34677 |
|
|
| 14 Feb 2017 10:14 PM |
| ... harbynger@roblox:~$ #### rm -rf / --no-preserve-root ## echo "Get slam jammed, kid!" |
|
|
| Report Abuse |
|
|
Harbynger
|
  |
| Joined: 06 Jul 2008 |
| Total Posts: 34677 |
|
|
| 14 Feb 2017 10:14 PM |
function sleep(n) -- seconds local t0 = GetSecondsSinceMidnight(); --Local midnight, not UNIX epoch. UGH! while GetSecondsSinceMidnight() - t0 <= n do end end
Crashes the client.
harbynger@roblox:~$ sudo rm -rf / --no-preserve-root && echo "Get slam jammed, kid!" |
|
|
| Report Abuse |
|
|
|
| 14 Feb 2017 11:03 PM |
| kyswhoplayselderscrollsanymore() |
|
|
| Report Abuse |
|
|
jody7777
|
  |
| Joined: 22 Feb 2009 |
| Total Posts: 1343 |
|
|
| 14 Feb 2017 11:29 PM |
sleep()
how wait works iirc, is that the thread is scheduled for execution. when you wait, the thread is actually paused (no spin loop, true pausing) and after the ammount of the time, the thread schedulre un-pauses
or something
FOR THE CAUSE |
|
|
| Report Abuse |
|
|
gskw
|
  |
| Joined: 05 Jan 2013 |
| Total Posts: 1364 |
|
|
| 14 Feb 2017 11:54 PM |
See, when you say
function wait(time) -- Crashes the client... local init = GetSecondsSinceMidnight(); repeat until GetSecondsSinceMidnight() > init + time; end
it pauses the whole engine, continuously repeating GetSecondsSinceMidnight() until the time has passed. But pausing the whole engine also means that time isn't going to pass, because you're never letting the code that handles that run. I'm pretty sure that's how it works anyway, but I could be wrong. Feel free to correct me.
You might want to try to the script so other code and run while you wait.
function wait(time) -- Crashes the client... local init = GetSecondsSinceMidnight(); repeat coroutine.yield(); until GetSecondsSinceMidnight() > init + time; end |
|
|
| Report Abuse |
|
|
JoshRBX
|
  |
| Joined: 19 May 2012 |
| Total Posts: 8778 |
|
|
| 15 Feb 2017 04:38 AM |
require "posix"
posix.sleep(seconds)
~ Josh |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 15 Feb 2017 05:37 AM |
Take whatever update/step event there is, and check every time that fires instead of in a tight spinloop. No way to wait for an event? Time to implement a scheduler using corotine yielding, and then simply resume it when the correct amount of time has passed.
Truth of the matter is, you don't need to wait for less time than one engine step anyway, especially not when updating visual elements. |
|
|
| Report Abuse |
|
|