So what I'm looking for is how to have variable variables:
Code: Select all
var{variable} = test
As in:
var987 = test1
var134 = test2
I realize this might be a little unclear..
~fenyctis
Code: Select all
var{variable} = test
As in:
var987 = test1
var134 = test2
Code: Select all
Dim var(1000)
varentry = 987
var(varentry) = test1
;Here is to show you that you can change the variable
varentry = 987-853 ; which is equal to 134
var(varentry) = test2
I remember mIRC, in which you could create such variables:srod wrote:No chance!![]()
Once a program is compiled, all variable names lose their meaning and translate to locations within the computers memory (the heap, the stack etc.)
The closest you'll get is to use an array or a linked list or perhaps even allocate some memory etc.
Of course, you could probably hack something together at the preprocessor stage, perhaps with macros etc.
Code: Select all
%var $+ 576 = test
Code: Select all
%var576 = test
The numbers are actually ClientIDs of connecting clients and I want to store some information they pass on (username, hostname etc.) Maybe you've got a good idea?SunSatION wrote:I think you should us arrays in this case.
I also think that variable variables are not possible to createCode: Select all
Dim var(1000) varentry = 987 var(varentry) = test1 ;Here is to show you that you can change the variable varentry = 987-853 ; which is equal to 134 var(varentry) = test2
Code: Select all
dim var(5000,5000,5000,5000)
The numbers are actually ClientIDs of connecting clients and I want to store some information they pass on (username, hostname etc.) Maybe you've got a good idea? I'm afraid of databases, because they require third-party software other people may not have. Having INI files storing these variables is unsafe and requires a lot of writing to the harddrive if my server is busy.srod wrote:Yes, but unless I'm mistaken, mIRC is not a compiler.
The only way you'll be able to implement something along these lines, is before compilation, e.g. with a macro.
**EDIT - too slow!
Code: Select all
Structure ClientInfo
ClientId.l
Username.s
Hostname.s
EndStructure
Dim clients.ClientInfo(999) ;Enough storage for 1000 clients.
clients(0)\Username="Bob"
Doesn't that array require a lot of memory?srod wrote:Assuming you're writing all this in Purebasic, then I wouldn't worry about databases. If I've understood correctly, then you could use SQLite easily enough - providing the server application is accessing it as if it were a stand alone app. SQLite simply requires that you copy a single .dll file onto the machine running the application; no activex controls, no MSDAC components, no fiddly ODBC setups.
However, providing the number of clients is not huge, why not use an array of structures:
You could even use a linked list instead.Code: Select all
Structure ClientInfo ClientId.l Username.s Hostname.s EndStructure Dim clients.ClientInfo(999) ;Enough storage for 1000 clients. clients(0)\Username="Bob"
Writing such an array out to an SQLite database is simplicity itself.