Scripts / Writing methodes (Scripters opinion)

Author
Message
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 27th Oct 2014 10:01
At the moment I am learning java and I had now a good idea:

write in a lua script methodes
load this in another lua script
use methodes names as commands

Is that something anybody want to use? Is this possible to implement? What´s your opinion!

My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
tomjscott
User Banned
Posted: 27th Oct 2014 14:55
If I understand you correctly, it looks like you want to create global functions for use in your scripts. That's standard stuff and scripters use that technique quite a lot in this community. Simply create a script file with your global commands and then use the require statement to include that file in your scripts for use. For example, if you have a file with global functions called myfunctions.lua then do the following at the top of the script you want to access those functions from:

require "myfunctions"

And be sure to put the myfunctions.lua in the scriptbank folder.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.0085
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 27th Oct 2014 16:40
thanks that is exactly what I need!

My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 28th Oct 2014 21:15
can you give me some example scripts? one with a methode and one which call it?
I get an error! File not found!

Thanks in advance

My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
Avram
GameGuru TGC Backer
18
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 29th Oct 2014 10:41 Edited at: 29th Oct 2014 10:42




I usually put package.path line in my global.lua and then I can just require "filename" in any lua script file.

tomjscott
User Banned
Posted: 29th Oct 2014 14:39
Yes, I had a feeling you'd get the error without the package.path command, but I couldn't remember the exact syntax. Thanks, Avram, for providing that.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.0085
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 29th Oct 2014 15:29
Thanks! I will test it when I was home.

My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 29th Oct 2014 23:07 Edited at: 29th Oct 2014 23:07
Ok it can load it but I always get an error!

Can someone look at the scripts and say me what I did wrong!



Thanks in advance

My dream is to develope games, which makes fun when I create it and fun when other people play it.

Attachments

Login to view attachments
PM
tomjscott
User Banned
Posted: 30th Oct 2014 04:55
Well, without detailed analysis, I'd say I see a couple of problems right off.

First, you never defined weapon_name, so you can't access it like an array element with something like weapon_name[e]. You need a global definition somewhere like:



Second, I'm not sure on this one, but I don't think you can call a function like giveback without parens. Maybe that should be giveback()

Other than that, I'd have to try in a real project and see what else I could dig up.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.0085
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 30th Oct 2014 11:37
Quote: "you never defined weapon_name"

it's already defined in the default global since they updated the weapon.lua script

however it doesnt actually seem to work in anything but the default scripts (for me anyway)

and yes if you put
it should work (if you dont get an error for the name)

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 30th Oct 2014 15:35
Quote: "however it doesnt actually seem to work in anything but the default scripts (for me anyway)"

this was the error! Thanks. I copy all in the weapon script and now it works.

My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM

Login to post a reply

Server time is: 2024-12-21 18:23:28
Your offset time is: 2024-12-21 18:23:28