Forum

> > CS2D > Scripts > String inside string?
Forums overviewCS2D overview Scripts overviewLog in to reply

English String inside string?

6 replies
To the start Previous 1 Next To the start

old String inside string?

Mami Tomoe
User Off Offline

Quote
I have no clue what to call it so I couldn't search for it too...

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

Results in

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 √

old Re: String inside string?

GeoB99
Moderator Off Offline

Quote
You cannot concatenate the id string before the variable when it's assigned. You would normally do like this as it's shown below:
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.

old Re: String inside string?

Mami Tomoe
User Off Offline

Quote
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

old Re: String inside string?

Nekomata
User Off Offline

Quote
Set this to your choice
1
hc.SERVERIP1 = "ip:port"

So, an example would be
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.

old Re: String inside string?

GeoB99
Moderator Off Offline

Quote
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.

old Re: String inside string?

TopNotch
User Off Offline

Quote
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
Log in to reply Scripts overviewCS2D overviewForums overview