|
Dr01d3k4Join Date: 2007-10-11 Post Count: 17916 |
while not Item do wait(0) print("Waiting for ...") end
Mine:
repeat wait(); until (item);
local function FunctionName(ArgumentOne, ArgumentTwo, ArgumentThree)
return {ArgumentOne, ArgumentTwo, ArgumentThree}
end
Mine (assuming this is what you're doing)
local function table.pack(...)
return {...};
end
Though I prefer moonscript: table.pack = (...) -> {...}
lib.FunctionName = FunctionName
lib.functionName = FunctionName
lib.function_name = FunctionName
Mine:
lib.functionname = functionName;
setmetatable(lib, {
__index = function (_, ind)
local i = ind:gsub("_", ""):lower();
if (lib[i]) then
return lib[i];
else
error(ind.." is not a valid member of lib");
end
end;
}); |
|
|
None of those are algorithms? |
|
TenalJoin Date: 2011-05-15 Post Count: 18684 |
^ |
|
|
@BlueTaslem
That's exactly what I thought.
_________________________________________________________________________
I possess 4 ROBUX and 164 tickets. |
|
|
closed as not a real question |
|
8SunTzu8Join Date: 2011-09-30 Post Count: 8199 |
lol
An algorithm checks all possibilities to decide the "best" solution to a problem.
I use algorithms for anti-TK situations and such. (Decide if a player should take damage or not, depending on the team of the shooter and the target's team).
Allied teams do not hurt one another, neutral cannot hurt or be hurt by any other team. Etc...
Anyway, these are all nifty functions, though. Don't they have a ":WaitForChild()" method now? (I can never seem to get it to work).
Philosopher, Creator, Clanner, Wiki Writer, and Student |
|
|
No... It doesn't...
What you're defining is similar to a cost function or heuristic...
An algorithm is a procedure to arrive at a desired result.
Your "algorithm" for team-attack detection would be so trivial no one would ever call it a "procedure," just a condition. |
|
8SunTzu8Join Date: 2011-09-30 Post Count: 8199 |
It goes through various checks for some values, and you use tables within a table for your inputs, along with the players and their teams. It's more complicated than:
if player.TeamColor == target.TeamColor then return end
Also, a heuristic is entirely different. With heuristics, the computer or program must learn from the past to arrive at solutions faster, but it only "estimates" a solution, but it can arrive at said conclusion much faster by checking less paths, or by not checking paths that it knows will not lead to fruition.
An algorithmic approach on the other hand will check all possibilities and return the best possible solution. (Which might be your desired result). It's much slower, but typically easier to program. Heuristics and Algorithms are mutually exclusive.
Philosopher, Creator, Clanner, Wiki Writer, and Student |
|
|
function GetTableIndex(Tab,Val,Func)
for i,v in pairs(Tab) do
if Func then
v = Func(v)
end
if v == Val then
return i
end
end
end
Example:
local Table = {"JoHnNy","BiLlY","BoB"}
print(GetTableIndex(Table,"billy",string.lower)) -- This should print 2.
Oh, and, reported for spam. |
|
|
|
I just read a definition of algorithm, I must now reveal my own.
"An explicitly defined procedure designed to solve a problem where the parameters of the problem tend to vary."
Examples of potential names for algorithms:
-How to solve a maze even if you've never seen a maze before
-How to build a rocking chair no matter who you are
-How to eat crab legs with a spork or a ladle
-How to math if calculator won't math |
|
|
|
It didn't have a point, I was just sharing something. It's a personal definition. |
|
BAUER102Join Date: 2010-04-03 Post Count: 5936 |
I generally use
for i, v in next, table do
-- This does execute faster than pairs
end
Also, I do often use
while true do
local delta = wait(0)
-- Do stuff with the delta
end |
|
|
I use repeat wait() until object everytime, and it works. Could you explain your problem a little more Quenty? |
|
Dr01d3k4Join Date: 2007-10-11 Post Count: 17916 |
--> repeat wait(); until (item);
Rather bothers me, because you're waiting even if the object exists. That's why I use a while loop. :/
repeat until (item and wait());
Unless Lua expects something between repeat and until, I'm not sure. |
|
|
A having lack of expected statements is valid. |
|
Dr01d3k4Join Date: 2007-10-11 Post Count: 17916 |
^
Took a bit to undertand what you meant :P |
|
|
Quenty i've had the same thing with repeat-loops waiting for objects. |
|
|
I know this is necrobumped..
but
"while not Item do wait(0) print("Waiting for ...") end"
why not just itemsParent:WaitForChild("item")
|
|
|
^ If you look at the KO - WO leaderboard script that the admins made a long time ago, you see that they didn't use object:WaitForChild() because WaitForChild wasn't a method back then. They later realized that it would be helpful to have that method, so they added it. I'm pretty sure the method was added earlier than 2013, but it may have not been known. |
|