GetTok || dofile

Started by Mötley, May 19, 2016, 01:44 AM

Previous topic - Next topic

Mötley

Discussion
Personally I have been using dofile for a very long time to keep the scripts more organized. But recently My scripting methods have changed a lot since the beggining,
Example::
//----------------------------------------------------------------------------------------------------------------------------------------------------
local dayNames          = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
local monthNames        = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
local currentDate       = date();
local futureDate        = date(time() + 3600);
local iRandom           = ( rand() % 3 );
//----------------------------------------------------------------------------------------------------------------------------------------------------    
 
When you have a few locals that will always become used and you do not want them all over your script
If you were to use this method in your main.nut, in the following dofiles the local becomes undefined

I want to see your response on why to keep dofile other than cleaner scripts,.



GetTok Okay I am well aware of how to use the code but it seems every time I attempt to use the code it's not defined.
Even the wiki ban returns this error for me and I find that irritating so I have to use other methods.
And that's without modifying the wiki ban..

KAKAN

Make the locals a global variable.
Paste this in variables.nut
//----------------------------------------------------------------------------------------------------------------------------------------------------
dayNames          <- ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
monthNames        <- ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
currentDate       <- date();
futureDate        <- date(time() + 3600);
iRandom           <- ( rand() % 3 );
//----------------------------------------------------------------------------------------------------------------------------------------------------     
Now load it using dofile and it should work :)

And about GetTok, it should be scripted, not available in the squirrel module by default.
oh no

Mötley

LOL You know.....
I learned that Method from Stoku,
I know the method you are speaking of and use to do this... Why I did not, I dont know, I guess It's because of Preventive local's.
Also knew about that dofile example from force VC:MP release of VBS scripts,.

I might consider going back to dofile. but honestly dofile does not always receive errors.,
so newbies would have heart attacks because of that, so I would have to think on that more.
Unless someone has a fix for that,. I have no problem with the difficult un defined errors a dofile has,. Like my current version is like FBS and I would get the error pointing at the script dofile/account.nut etc,,.

But thats easy enough for myself and helpful that its pointing it out, but for newbies trying to find the error would be a nightmare so I still just do not know. Now maybe I could script a catch(e) like exec to somehow retrieve the error.. I dont know yet and would prefer to not waste my time on that and might just keep everything in the main.nut,

KAKAN

dofile(filename,true) might fix your problem.
Though, I didn't get you correctly.
oh no

Mötley

I have never seen true added to dofile.

:: As I said that dofile never really catches the errors in just says error on dofile. leading you to where that error is located., So if there is a way to use a catch(e) to catch the error after the dofile or something then that would work.
But I found that dofile does not fetch the errors correctly, I do not want to release something that newbies will always ask questions on, I can imagine it now KAKAN and it's a Nightmare..

So I am considering one main.nut instead... unless there is a fix for the newbies

Thijn

Quote from: KAKAN on May 19, 2016, 03:27 PMdofile(filename,true) might fix your problem.
Though, I didn't get you correctly.
The true only gives proper errors on syntax errors, not anything else. As stated in the docs:
if the optional parameter 'raiseerror' is true, the compiler error handler is invoked in case of a syntax error. If raiseerror is omitted or set to false, the compiler error handler is not ivoked.

KAKAN

Quote from: Thijn on May 19, 2016, 04:31 PM
Quote from: KAKAN on May 19, 2016, 03:27 PMdofile(filename,true) might fix your problem.
Though, I didn't get you correctly.
The true only gives proper errors on syntax errors, not anything else. As stated in the docs:
if the optional parameter 'raiseerror' is true, the compiler error handler is invoked in case of a syntax error. If raiseerror is omitted or set to false, the compiler error handler is not ivoked.
And that's what Motley asked I think.
oh no

Mötley

Okay that is very interesting. And I mean VERY!!
I wish Force did this in his really old release of FBS, I would of known about this a really long time ago,.

catch(e) is stupid but sounded interesting.

I will take the time to re do the dofiles in the end.


Okay GetTok

http://wiki.vc-mp.org/wiki/Scripting/Squirrel/Functions/BanIP
Does not work (does not exist) I even copied and pasted a command I had in LU as GetTok works just fine in LU for me in VCMP its a nightmare, I cant even use a normal reason of ban. and I have to use this method to do more which I really hate

local params = split(text, " ");
params[ 0 ].tointeger ( );
params[ 1 ].tointeger ( );
params[ 2 ].tointeger ( );


KAKAN

GetTok and NumTok are planned to implement, but they're in low priority. So, you have to manually implement through scripts.
oh no

Mötley

That clears that up but the wiki ban should be updated then..

KAKAN

Quote from: Mötley on May 19, 2016, 05:16 PMThat clears that up but the wiki ban should be updated then..
The wiki is a mess. I always use LU's wiki to get the functions or Murdock's wiki.
oh no

Mötley

Murdock's wiki :o?? I actually cross mix them as well, With common sense better examples can be created