English ToTable

27 replies
Goto Page
To the start Previous 1 2 Next To the start
17.02.13 07:54:19 am
Up
It is supposed to make the variable's value into 1 every 1.5 seconds.
The first attack works, but it doesn't the second time.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
addhook("attack","tank_attack")
function tank_attack(id)
     if tankatk[id]==1 then
          tankatk[id]=0
          timer(1500,"tank_reload",id)
          parse("spawnprojectile "..id.." 47 "..player(id,"x").." "..player(id,"y").." 300 "..player(id,"rot"))
     end
end

function tank_reload(id)
     tankatk[id]=1
end

Note: This is just a part of the script.
edited 1×, last 17.02.13 01:51:25 pm
17.02.13 08:26:44 am
Up
Suprise
BANNED
Offline Off
That's because when you say: 'if tankatk[id]==1 then' then you say that tankatk[id]=0. And because it's 0 the afterwards commands won't work (they would work if tankatk[id]=1)

Code:
1
2
3
4
5
6
7
8
9
10
11
12
addhook("attack","tank_attack")
function tank_attack(id)
     if tankatk[id]==1 then
          timer(1500,"tank_reload",id)
          parse("spawnprojectile "..id.." 47 "..player(id,"x").." "..player(id,"y").." 300 "..player(id,"rot"))
          tankatk[id]=0
     end
end

function tank_reload(id)
     tankatk[id]=1
end


I think this is the problem
17.02.13 08:35:00 am
Up
@user Suprise: It still only fires once, tank_reload still doesn't work.
17.02.13 08:39:15 am
Up
VADemon
User
Offline Off
Code:
1
timer(1500,"tank_reload",tostring(id))
17.02.13 08:50:14 am
Up
Gajos
BANNED
Offline Off
This is didn't tested:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
addhook("attack","tank_attack")
function tank_attack(id)
     if tankatk[id]==1 then
          tankatk[id]=0
          timer(1500,"tank_reload","id")
          parse("spawnprojectile "..id.." 47 "..player(id,"x").." "..player(id,"y").." 300 "..player(id,"rot"))
     end
end

function tank_reload(id)
     tankatk[id]=1
end
Banned for Hacking/Cheating in CS2D /DC
17.02.13 09:13:23 am
Up
None works, I think my script is cursed.
17.02.13 09:17:21 am
Up
Alistaire
User
Offline Off
user Obviously Exactly Myself has written:
None works, I think my script is cursed.


Could only be something else in your script. Or you didn't declare tankatk in the first place.
IMG:http://i.imgur.com/5zhwOTP.png
17.02.13 09:36:13 am
Up
Flacko
User
Offline Off
This
user VADemon has written:
Code:
1
timer(1500,"tank_reload",tostring(id))


And this:
Code:
1
2
3
function tank_reload(id)
     tankatk[tonumber(id)]=1
end
17.02.13 09:59:35 am
Up
user Alistaire has written:
Could only be something else in your script. Or you didn't declare tankatk in the first place.
Checked it, I did.

@user Flacko: Thanks, it works.

--EDIT--

Now the save function doesn't work.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function tank_load(id)
     local l
     if (player(id,"usgn")>0) then
          f=io.open("sys/lua/JeloTanks/Save Data/"..player(id,"usgn")..".sav","r")
          if (f~=nil) then
               for line in f:lines() do
                    l=toTable(line)
                    uphealth[id]=tonumber(l[1])
                    upspeed[id]=tonumber(l[2])
                    uprange[id]=tonumber(l[3])
                    uprate[id]=tonumber(l[4])
                    points[id]=tonumber(l[5])
                    break
               end
               f:close()
          end
     end
end
edited 1×, last 17.02.13 12:25:10 pm
17.02.13 12:27:43 pm
Up
Alistaire
User
Offline Off
user Obviously Exactly Myself has written:
Now the save function doesn't work.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function tank_load(id)
     local l
     if (player(id,"usgn")>0) then
          f=io.open("sys/lua/JeloTanks/Save Data/"..player(id,"usgn")..".sav","r")
          if (f~=nil) then
               for line in f:lines() do
                    l=toTable(line)
                    uphealth[id]=tonumber(l[1])
                    upspeed[id]=tonumber(l[2])
                    uprange[id]=tonumber(l[3])
                    uprate[id]=tonumber(l[4])
                    points[id]=tonumber(l[5])
                    break
               end
               f:close()
          end
     end
end


Can you EVER say what the error is instead of just sending shit saying it's not working? I mean we don't know if ToTable works, if uphealth[id], upspeed[id] etc exist, nothing.
IMG:http://i.imgur.com/5zhwOTP.png
17.02.13 12:36:04 pm
Up
@user Alistaire:
LUA ERROR: sys/lua/server.lua:256: attempt to call global 'toTable' (a nil value)

Everything else exists.
17.02.13 12:38:08 pm
Up
Alistaire
User
Offline Off
user Obviously Exactly Myself has written:
@user Alistaire:
LUA ERROR: sys/lua/server.lua:256: attempt to call global 'toTable' (a nil value)

Everything else exists.


Well then it appears, toTable isn't an actual function.
IMG:http://i.imgur.com/5zhwOTP.png
17.02.13 12:40:09 pm
Up
@user Alistaire: It worked before, but I don't know why I doesn't work right now.
17.02.13 02:26:00 pm
Up
Flacko
User
Offline Off
Then show us how and where you declared toTable.
17.02.13 03:04:51 pm
Up
I forgot. It doesn't show any errors if I removed this part of the script, However.
17.02.13 03:27:02 pm
Up
Alistaire
User
Offline Off
user Obviously Exactly Myself has written:
I forgot.


Open the script
Ctrl+f
Type "toTable"
Copy the function
Paste it here
IMG:http://i.imgur.com/5zhwOTP.png
18.02.13 11:32:11 am
Up
It seems that there was only one line with the word "ToTable".
I forgot how to make a proper load system. BTW, that load part was copied & pasted from my old script that was two years ago.
So actually, I am now trying to ask how to make the load function work.
More Info: I used "tank_load(id)" on the "join" hook to load the USGN User's data.
18.02.13 02:18:33 pm
Up
UnkN
User
Offline Off
Paste it in script.
Code:
1
2
3
4
5
6
7
8
function totable(t,match)
     local cmd = {}
     if not match then match = "[^%s]+" end
     for word in string.gmatch(t, match) do
          table.insert(cmd, word)
     end
     return cmd
end
Nothing here.
18.02.13 02:33:31 pm
Up
uaiek
User
Offline Off
Use "ToTable" not the "toTable" one.
Declaring function name is 'case-sensative', so write the copy of the declared name function to call it.
It seems to be good.
18.02.13 03:17:16 pm
Up
@user UnkN & user uaiek: Loading is still not working.
To the start Previous 1 2 Next To the start