Author Topic: Files  (Read 2245 times)

fileobject.close();  - save the file if writing/appending, and allow other programs to access the file.
That's why a lot of languages require that you "close" the file.

Also: How to use schedules?

Object oriented schedules:
object.schedule(time in ms, function [arg1, arg2, argx...]); - Example %player.schedule(1000, lolfunction, stuff, %cake, %gold); will call %player.lolfunction(stuff,%cake,%gold);

Non-Object oriented schedules:
schedule(time in ms, 0 (no idea what else would go here), function, args and stuff); - example schedule(1000,0,banBLID,%client.bl_id,-1,"hur ur b& 4ever"); will call BanBLID(%client.bl_ID,-1,"hur ur b& 4ever"); after one second.

Schedules can also be applied to global variables and object values in case you need to cancel them for any reason.
global variable or object value = schedule(time in ms, 0, function, args);
or
global variable or object value = object.schedule(time in ms, function, args);

To cancel:
cancel(global variable or object value);

example:
$lolsched = schedule(10000,0,lolfunction);
and somewhere else
cancel($lolsched); will make so lolfunction will NOT be called after 10 seconds.

Wow. Thanks for all the wonderful help.

Remember that if you reassign $lolsched, the schedule will still continue

$ls = schedule(10000, 0, echo, pe); $ls = schedule(5000, 0, echo, 5000);

The variable $ls points to the specific schedule, and does not represent the schedule itself.
Calling a cancel($ls); after that will only cancel the 5000 one.

Forgot to mention that, and it is a very important point.

In function/schedule loops, I ALWAYS cancel before calling another schedule and you should too.

What if you need to do two at the same time?

Use different variables.
Example:

$saveloop = schedule(300000,0,saveloop);
%client.printloop = %client.schedule(1000,showStatsPrint);

Oh, I see what you mean now. I was confused.

No. You would need to make your own functions.
Not sure how banning would work, however kicking would just find the client and delete them.

/ban [id] [id] [time] [reason]

serverCmdBan(client,id,id,time,reason)

commandToServer('ban', "", "bl_id", "time", "reason");
Use it on someone else's server if you want a multi-word reason
The second field is supposed to be the client's objectID, but it can be blank if the person is not in the server.

Using serverCmdBan would require a super admin to actually be on the server for the command to work, and commandToServer is client sided.

Using serverCmdBan would require a super admin to actually be on the server for the command to work
No. The host has to do it.

No. The host has to do it.
This is coding help Kalph, not console help.

This is coding help Kalph, not console help.
No, this is Patrick.

I'm posting this because it is somewhat related to the topic, this code that will list all files in a folder, which I found very useful and I haven't seen it anywhere else on the coding forums (actually found this code in blockland v1.6 mods). So config/client/ is the path to search in, and the * is a wildcard

Code: [Select]
for(%file = findFirstFile("config/client/*"); %file !$= ""; %file = findNextFile("config/client/*"))  
{
//This is where you'd add %file to a list or something, it returns the file path, name and extension. (ex:config/client/prefs.cs)
}