Author Topic: How to link scripts  (Read 4671 times)

0 Members and 1 Guest are viewing this topic.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
How to link scripts
« on: 25 July, 2006, 19:29:47 »
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)

PtokaX forum

How to link scripts
« on: 25 July, 2006, 19:29:47 »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 725
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: How to link scripts
« Reply #1 on: 25 July, 2006, 19:41:28 »
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.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: How to link scripts
« Reply #2 on: 25 July, 2006, 20:08:21 »
Hi all

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

Good luck for everyone :)

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: How to link scripts
« Reply #3 on: 25 July, 2006, 20:24:04 »
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 :)

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: How to link scripts
« Reply #4 on: 25 July, 2006, 20:57:40 »
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 :)

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 725
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: How to link scripts
« Reply #5 on: 25 July, 2006, 21:29:16 »
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.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 725
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: How to link scripts
« Reply #6 on: 25 July, 2006, 21:32:41 »
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.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: How to link scripts
« Reply #7 on: 25 July, 2006, 22:30:04 »
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)
« Last Edit: 25 July, 2006, 22:31:43 by Naithif »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 725
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: How to link scripts
« Reply #8 on: 25 July, 2006, 22:47:42 »
Sure thing. Attached.
Everything could have been anything else and it would have just as much meaning.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: How to link scripts
« Reply #9 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 :)

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 725
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: How to link scripts
« Reply #10 on: 25 July, 2006, 22:57:00 »
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...
« Last Edit: 25 July, 2006, 23:14:28 by bastya_elvtars »
Everything could have been anything else and it would have just as much meaning.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: How to link scripts
« Reply #11 on: 25 July, 2006, 23:42:33 »
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 :)



Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 725
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: How to link scripts
« Reply #12 on: 25 July, 2006, 23:52:54 »
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.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: How to link scripts
« Reply #13 on: 25 July, 2006, 23:58:00 »
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 :)

PtokaX forum

Re: How to link scripts
« Reply #13 on: 25 July, 2006, 23:58:00 »