English String inside string?

6 replies
Goto Page
To the start Previous 1 Next To the start
29.05.16 04:24:30 pm
Up
Mami Tomoe
User
Offline Off
I have no clue what to call it so I couldn't search for it too...

Code:
1
2
3
if hc.SERVERNAME ..id == nil then
  hc.SERVERNAME ..id = '(Empty | '
end


Results in

Code:
1
2
3
LUA ERROR: sys/lua/server.lua:23: '=' expected near '..'
 -> [C]: in function 'dofile'
 -> [string "dofile("sys/lua/server.lua")"]:1: in main chunk


I know I'm doing it wrong but I just tried for like the past 10 minutes and I have no clue what to do
I would like to add there is no hc.SERVERNAME[id] since this is in a loop and I want to find 9 hc.SERVERNAME like that:

hc.SERVERNAME1
hc.SERVERNAME2
hc.SERVERNAME3
etc..

Pliz help me
oh my cat say hi √
fish
29.05.16 04:56:54 pm
Up
GeoB99
Moderator
Offline Off
You cannot concatenate the id string before the variable when it's assigned. You would normally do like this as it's shown below:
Code:
1
hc.SERVERNAME = hc.SERVERNAME .. id '(Empty | '

However there's something that you should be aware of. Since the strings in Lua are immutable, each new concatenation with the same variable string creates a new string object. That would result in a poor performance due to successive concatenations into a single string. Also, note that it might occur unexpected behaviours whilst you run the code since I don't have your script to test whether it gives optimal results with this fix or not.
29.05.16 05:21:12 pm
Up
Mami Tomoe
User
Offline Off
Spoiler >


Edit: Problem solved
But I have a new problem, how to get the server IP in a script? (including port)
edited 2×, last 29.05.16 05:48:01 pm
fish
29.05.16 06:15:40 pm
Up
Nekomata
User
Offline Off
Set this to your choice
Code:
1
hc.SERVERIP1 = "ip:port"


So, an example would be
Code:
1
hc.SERVERIP1 = "192.168.0.1:80"


You have to manually set the IP and port values of a server you want to reroute to.
29.05.16 06:30:55 pm
Up
Mami Tomoe
User
Offline Off
Yes but I want the actual server's IP, like this:

Code:
1
game("sv_name")
fish
29.05.16 07:19:54 pm
Up
GeoB99
Moderator
Offline Off
There's no way you can achieve this with the current CS2D library unfortunately. The IP and port of the server must be written manually by yourself for each indexed table.
29.05.16 07:54:14 pm
Up
TopNotch
User
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
addhook("say", "_say")

function _say(id, txt)
     if txt:sub(1,4) == "!bla" then
          local handle = io.popen("curl ipecho.net/plain; echo")
          local result = handle:read("*a") .. ":" .. game("port")
          msg(result)
          handle:close()
     end
end

You will need "curl" installed on your machine.
To the start Previous 1 Next To the start