How to link scripts
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

How to link scripts

Started by Naithif, 25 July, 2006, 19:29:47

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Naithif

Hi all

I would like to ask that how can i link scripts together?  ???
I've thought of something like that there's a main lua script in the scripts folder, and some more "part" scripts in a directory, and i would like the main script to execute them, so PtokaX only load directly 1 script, but uses every function from every script.

I'll try to show it, as it's not really clear i think -->

1.) There's a main.lua in the PtokaX\scripts folder
2.) There're some other luas in a directory let's call it PtokaX\scripts\part
3.) Upon starting the hub, it executes main.lua which is the only script in PtokaX\scripts
4.) main.lua calls the other scripts in PtokaX\scripts\part directory, with all of their function working

I've only found a "require" function referring to the "part" script, but i doubt it would be enough alone, or is it?

Thanks for any help / advice  :)

(edit: correcting my english)

bastya_elvtars

require does openm the file, and executes it (same as dofile) if no other statements are given.
Everything could have been anything else and it would have just as much meaning.

Naithif

Hi all

So require should be enough? Thanks b?stya_elvt?rs  ;)

Good luck for everyone :)

Naithif

Hi all

Errm, maybe i'm totally noob at this (that's right) but if i call a require for each script, then it only accepts the last  :(

Is there a way where all scripts can be loaded in the same require function, or it's done some other way? ???
I need to load a whole bunch of scripts (7 at least)

Thanks for any help / advice :)

Naithif

Hi all

Eerrm no change, only the last is loaded :(

I've used multiple times
Ex.
dofile("path/scriptname1.lua")
dofile("path/scriptname2.lua")
dofile("path/scriptname3.lua")
dofile("path/scriptname4.lua")
To surprise, the same as with require...
Only the last worked, i've swapped them, and then the actual last worked...

I've no intention to merge all of "my-own-made" scripts into one "huge" script, i only would like to have them separated, it's easier for me to see through - if only this problem could be solved...

Let's see again, i have made some scripts, and i want to have them separated, and not to have PtokaX load 7-10+ script, i would like to use a "server" or "spider" script, that would execute all of the scripts, thus starting them...
Is there any way?  ???

Thanks for any help / advice :)

bastya_elvtars

Well, Lua 5.1 module system makes this possible. For instance, you can load scripts with declaring them as modules, placing right to the top:

module("scriptname",package.seeall) -- package.seeall is needed to tell the module that it can see the global environment

Now all under this (functions, etc.) will get into the namespace scriptname, thus can be called like scriptname.NewUserConnected(user). To call them in your spider all at once, you need to run through _G (the global environment) and check whether the given table in _G contains a table which has a NewUserConnected field that is a function value. Now these can be stuffed into another table which is looped on NewUserConnected in the spider. Hope I was clear.

-- // EDIT

It only executes the last because you keep redeclaring PtokaX global events (you always redeclare NewUserConnected for example, thus the last guy wins. :P)
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

We can speak @ ro.4242.hu if English is too hard for you, but on the other hand, Hungarian is too hard for me (at least in such contexts).  8)

I am not aware of your skills in LUA, but be warned that this is not an easy part.
Everything could have been anything else and it would have just as much meaning.

Naithif

#7
Hi all

Thanks, but it's not my english what's the problem here i've even made some "bit complicated" games/utils in VB and VC++ (mostly VB)...
(i've made some progz that had 2000lines of data there, but i've seen things clearer there then in lua...)

I would like to ask for an example to help thing clear up, i'm not really the one who learned lua from books, i've learned mostly by reading this forum and trying-till-it-won't-work ;D
(ATM i'm on a main script, it has many parts, that's why i need this "example")
I've started bytranslating, then modding, then making my own scripts... I've not really used the lua handbook, i mostly learned by examples of how's things done...

So, clear up, i ask for a "straight-forward-example" ( ;D) of for example 4 scripts loaded by one "spider" script. (please  :D )

(I was wondering that "daisy chain" way should work? I don't wanna try it, just asking)

Thanks for any help / advice :)

(edit: even i make mistakes writing, but every time???  ;D ;D corrected type errors)

bastya_elvtars

Everything could have been anything else and it would have just as much meaning.

Naithif

Hi all

LoooooooooooooooooL
I don't think i even had 1% chance to get it done, even with the handbook  ;D


Thanks so much for your help B?stya :)

bastya_elvtars

#10
Quote from: Naithif on 25 July, 2006, 22:53:54
Hi all

LoooooooooooooooooL
I don't think i even had 1% chance to get it done, even with the handbook  ;D


Thanks so much for your help B?stya :)

Well, that Main() function in the mainscript has been given birth just now, haven't experimented with package.loaded before, but this is also the new way LawMaker is gonna be structured.  ;D

-- //EDIT

I expect you to post back the results...
Everything could have been anything else and it would have just as much meaning.

Naithif

Hi

Eeeerrr how to tell you

There's a little problem with this script...

Well, here's what working:

script1 - not working
script2 - not working
script3 - not working
script4 - not working
script5 - unknown
script6 - it works, but the registration of the bot that's regged here's gone (appears offline) (???)
script7 - looks like it's working

Now i'm really confused  ;D

Thanks for your help anyway :)



bastya_elvtars

Well, this is hard to track down without the code. :-P
Anyway, I am off to sleep, till then attach those scripts and we'll look into the problem tomorrow.
Everything could have been anything else and it would have just as much meaning.

Naithif

Hi

I don't really like the idea of posting my script half made  :(

Maybe i'll when i'm ready, but until then looks like i must use them separated :(
I simply don't want to merge them into 1 script :(

Thanks anyway for your help :)

SMF spam blocked by CleanTalk