Hi, dear lua friends, I was unable to post since 1 year, because I closed my hub.. but I always loved scripting.
I used to post in the earlier forum! Someone will remember some of my scripts, like Lucifer 666 AntiAdv and Crazy Animals Bot! I hope so.
Well, I decided some day ago to come back with lua scripting, only to terminate a huge script I'm bringing from 3 years.
The reality is: I met a problem and after months it killed me and my will to carry on scripting. I take to you my drama: if you give me an hand, I'll reborn.
I isolated the problem compiling a new lua, here it is:
--I want to separate the values of two arrays.
--Simply type:
-- call arraya
-- look arraya
-- call arrayb
-- look arrayb
--
--and then look arraya
--
--When I call arraya and then arrayb, the value of the first one is overwrited by the second one.
-----------------------------------------------------------------------------
arraya={}
arrayb={}
value={}
-----------------------------------------------------------------------------
function DataArrival(user, phr)
if ( strsub(phr, 1, 1) == "<" ) then
_,_,com, other = strfind(phr, "%b<>%s+(%S+)%s*([^|]*)%|$");
local versus=GetItemByName(other);
if com=="call" then
if other=="arraya" then first(user, arraya, 10);
elseif other=="arrayb" then first(user, arrayb, 5);
end
end
if com=="look" then
if other=="arraya" then tellme(user, arraya);
elseif other=="arrayb" then tellme(user, arrayb);
end
end
if com=="kill" then
check(user);
if target~=nil then
boom(user, target);
end
end
end
end
-----------------------------------------------------------------------------
function first(user, generalarray, number)
if generalarray[user.sName]==1 then
SendToAll(" Don't try to recall the array!");
else
generalarray[user.sName]=1;
value[generalarray[user.sName]]=number;
SendToAll(" Array called");
end
end
-----------------------------------------------------------------------------
function check(user)
if other=="arraya" then Checkarr(user, arraya)
elseif other=="arrayb" then Checkarr(user, arrayb)
else target=nil;
end
end
-----------------------------------------------------------------------------
function tellme(user, generalarray)
if generalarray[user.sName]==1 then SendToAll(" Array exists; value: "..value[generalarray[user.sName]]);
else SendToAll(" Array is null");
end
end
-----------------------------------------------------------------------------
function Checkarr(user, garr)
if garr[user.sName]==1 then
target=garr;
else
target=nil;
end
end
-----------------------------------------------------------------------------
function boom(user, hit)
hit[user.sName]=nil;
SendToAll(" Array killed");
end
-----------------------------------------------------------------------------
Hope 2 be explicit.
Well, then as being your fan, i MUST help you. :P
local versus=GetItemByName(other);
if no such user logged in then it won't work.
I cannot understand your problem atm. MAby an example will help.
QuoteOriginally posted by bastya_elvtars
Well, then as being your fan, i MUST help you. :P
Such a satisfaction :) Happy to be identified as not a newbie
I think local versus isn't the problem (it seems it's just a old piece of script, coz I don't recall var versus later in this script).
Anyway, I try to be more clear.
User 1 play a sphere on the table.
The sphere has 10 hit point.
User 2 can hit the sphere to lower the points.
But.
If User 2 has a sphere too, when he hit User 1's sphere he hit his too.
I can't control the arrays to get them separate.
Array[User1] seems not 2 control only User1's arrays.
E.G.
I've got the function LOWERPOINTS[target] that lower the target points, in this way:
POINTS[target]=POINTS[target]-5
target can be Sphere[User1] or Sphere[User2].
I don't think the problem is an array included in another, or something else. It's a theoretic problem.
1st of all welcome back.
now the script.
why not a nested table??
would work a lot faster and should make it a lot easier.
plop
QuoteOriginally posted by plop
1st of all welcome back.
now the script.
why not a nested table??
would work a lot faster and should make it a lot easier.
plop
Oh plop, I remember you and RabidWombat from the old forum ;) Have I lost something important?
1)Do u know why array method doesn't work? I wanna try this, if a solution is possible, or I must change a lot of code (script is quite long and complex).
2)Give me a nested table example applied to this event. Unfortunately I must to rehabilitate after months of laziness ;)
Thanks, bye
there is something to do with target. hard to predict as i cannot test it as my net is limited atm. :(
-- // edit
I looked at your script again. What if you used a nested table (as plop said before) like this:
spheres=
{
["user1"]={1,2,3},["user2"]={6,3,8,},
}
Would kinda make sense.
a normal table seems fine 2 if i get your idea correct.
execute the next example with the lua command line.
tPlayers = {
["player1"] = 1,
["player2"] = 1,
["player3"] = 1,
["player4"] = 1,
["player5"] = 1,
["player6"] = 1,
["player7"] = 1,
["player8"] = 1,
["player9"] = 1,
["player10"] = 1,
}
for i=1, 50 do
local iPlayer1 = random(1,10)
local iPlayer2 = random(1,10)
tPlayers["player"..iPlayer1] = tPlayers["player"..iPlayer1] + 1
tPlayers["player"..iPlayer2] = tPlayers["player"..iPlayer2] - 1
end
tTemp = {}
iLow = 0
iHigh = 0
for a,b in tPlayers do
if tTemp[b] then
tTemp[b] = tTemp[b].." / "..a
else
tTemp[b] = a
end
if b > iHigh then
iHigh = b
elseif b < iLow then
iLow = b
end
end
for i=iHigh, iLow, -1 do
if tTemp[i] then
print(i.." = "..tTemp[i])
end
end
plop