PDA

View Full Version : LS script and LSC question (newbie)



FrankyGTH
01-27-2009, 02:38 AM
dear LW friends:-)

hello script guys and nice Lightwave Users!

I have some simple question about LS Script and LSC Scripts/Plugins...
I am playing around with script example but without success or with no really fun at all ;)

a) what is the different between these two kinds???
b) documentation could help or a link to it ;)
c) would like to develop some simple *.ls scripts and improve it... where can I find a useful editor for it???

d) why doesn't run elder scripts with the current LW 9.x version???

perhaps somebody can help, would be very nice,

my aim:
e) I will write an ambient (light) script
f) something with Emitter FX too:-)

best wishes for all here and Lightwave too :-D

Franky GTH with sunshin in my heart :-)

Matt
01-27-2009, 02:54 AM
LS = LScript

LSC = Compiled LScript

Compiled LScripts don't run any faster, they just allow you to protect your code by making it hidden if you so wanted.

Not the official documentation, but MUCH better:
http://www.mikegreen.name/Lscript/Lscript%20Index.html

The official documentation:
http://www.newtek.com/lightwave/developers.php

You can use the two programs in your Programs folder in your LightWave install:

lsed.exe - LScript Editor
lsid.exe - LScript Interface Designer

But most people just use their preferred text editor of choice, I use ConText (http://www.contexteditor.org/).

Some older scripts might not run because specific commands / features they are using have changed in their behaviour. Although sometimes a script just needs the version number putting up to the latest version and it runs fine.

There are also loads of LScripts that have been given away freely, with the code commented, check the forums.

Hope that helps!
Matt

evenflcw
01-27-2009, 02:55 AM
(1) LS is plain text so you can read the code in Notepad. LSC is compiled and is not plain text. By compiling you make it harder for others to see your code and the compiler also has some additional options that will provide copy protection. Compiling can alos bring together several source files into a single LSC file.

(2) Go to Lightwaves Developer page at www.lightwave3d.com and download the lscript documentation. It should mention something. The explanation of the compiler interface and options might be in the regular LW manuals. Not sure.

(3) Your lightwave installation should include an LScript Editor and an LScript Interface Designer (gui code generator). But the editor is buggy and may crash on undo, save and I'm sure lots of other cases. So I would not recommended it as the main aditor to use. Use Notepad++ or that other one I can't remember the name of (for which someone I also can't remember the name of created a syntax highlighting preset for). Search the forum! The LScript Editor does include a syntax checker that you might want to use from time to time, when you can't find errors just from error messages and debugging alone.

(4) That's on a script by script basis. When running a script LW will check what versions the script has declared itself to be compatible with. And it might be for no good reason. If you find such a script contact the author or ask for help in the forum.

(5,6) Good luck!

EDIT: What he said! :)

FrankyGTH
01-27-2009, 03:31 AM
:-D short reply...

thank your dear dan and matt !!! :-)))

... by the way...

what is the sdk good for??? it includes c++ code, it's the right way to build lw plugins???

have a nice day both of you :-)
I will read all infos and documentations I can perhaps use for my first steps:)

ahhh... one more:

the content cd of lightwave (I am working with 8.3, 8.5) includes also script or plugin examples???

bye, FrankyGTH
after that I will check the new trial version of LW 9.6 !

good to now here at the board I can perhaps find more help! you are welcome! :)

Matt
01-27-2009, 03:47 AM
:-D short reply...

thank your dear dan and matt !!! :-)))

... by the way...

what is the sdk good for??? it includes c++ code, it's the right way to build lw plugins???

have a nice day both of you :-)
I will read all infos and documentations I can perhaps use for my first steps:)

ahhh... one more:

the content cd of lightwave (I am working with 8.3, 8.5) includes also script or plugin examples???

bye, FrankyGTH
after that I will check the new trial version of LW 9.6 !

good to now here at the board I can perhaps find more help! you are welcome! :)

Yes, the SDK is mainly for C++ developers wanting to write plugins (.p files). These allow much more access than the scripting language, and run considerably faster.

You can also look in your Programs > Plugins folder for many NewTek scripts. Most are not fully commented though, but some are. I know I found out a few things looking at some of those.

If you do a search for threads I've starting with the keyword "Script" in the 'Titles Only' option, you will find a few scripts I've written that are fully commented.

Cheers
Matt

FrankyGTH
01-27-2009, 06:16 AM
my first try :-)

but I have done a mistake... it doesn't run :-( but I am thinking it's just a simple word or item missing... I wish to run it.

@warnings
@name text

main
{
// This is a comment.
text = “Hello Franky GTH, this is my first lw script!”;
info(text);
}

btw: the "text.ls" script of the lw script/modeler folder also doesn't run, must laugh... :D

have downloaded the 9.6 trial version, wow!!! what a great 3d app! :-)))

perhaps matt or dan can you have a look at the script???

best wishes, FrankyGTH

Matt
01-27-2009, 06:34 AM
If you want a script to run in Modeler, you need to put the following line somewhere at the top:

@script modeler

If you want it to run in Layout then the line becomes:

@script generic

There are other types, but these are the two main ones. Essentially you need to let LightWave know what type of script it is so it knows what to do with it.

FrankyGTH
01-27-2009, 07:51 AM
hi matt:)
hi dan:)

can you check the script it for me again ???
my script

@script modeler

main
{
// This is a comment.
text = “Hello World!”;
info(text);
}

it doesn't run with the modeler, although I have done everything right, but get an error message

In main, line 6, found "W", expecting '@'
line: text = Hello World!

hmh... don't know how it should be done correctly ?

perhaps you can have a closer look for it ;)

best regards, FrankyGTH

Matt
01-27-2009, 08:11 AM
Ahhhhhh, you're using the wrong quotation marks!

Use these ones " " (above the 2 on my keyboard).

And not “ ”.

See the difference " " vs “ ”

That caught me out once, took me ages to figure it out! :)

FrankyGTH
01-27-2009, 08:33 AM
ooohps:-D

yes, you are quite right, the damned quotation marks, rummms! :lol:
I have copied the script and perhaps the little devil gets between the script lines (must laugh)

@script modeler

main
{
// This is a comment.
text = "Hello dear FrankyGTH, this is my first Lightwave script!";
info(text);
}

now the script runs as well as I wish...
more I send it here perhaps... in the next days :-D

many thanks, matt, don't know why I am so confused today ;)

but with this entry I have fun to work with a new script...

see you and the next script will run without mistakes, I promise you! :-)))

ciao and servus, FrankyGTH

Matt
01-27-2009, 11:34 AM
Sure thing, feel free to ask more questions, it's good practise for me too! :D

FrankyGTH
01-27-2009, 11:34 AM
hi matt, one script again, it runs, but started in the ending with an error line...
info("Position: ",light.getPosition(frame));
is unknown, why??? the script is one basically part of my light_script with ambient light ;)

@version 2.2
@warnings
@name "LightsTest_FB"
generic

//Set Globals
{
light = Light();

// Display some Data Members.
info("Name: ", light.name);
info("Type: ", light.type);

//Display some Methods.
info("Position: ",light.getPosition(frame));
info("Rotation: ",light.getRotation(frame));
info("Scaling: ",light.getScaling(frame));
info("Ambient: ", light.Ambient(frame));
info("Color: ", light.Color(frame));
}

this script is from here:

http://www.mikegreen.name/Lscript/Lscript%20Index.html

perhaps you find a solution, have a nice evening, sorry for my silly questions ;)))

ciao, FrankyGTH

FrankyGTH
01-28-2009, 07:42 AM
hi all,
perhaps somebody can test the light-script with the current lightwave release 9.6???
I have worked some years with 8.3 ;)

@version 2.2
@warnings
@name "LightsTest_FB"
generic

//Set Globals
{
light = Light();

// Display some Data Members.
info("Name: ", light.name);
info("Type: ", light.type);

//Display some Methods.
info("Position: ",light.getPosition(frame));
info("Rotation: ",light.getRotation(frame));
info("Scaling: ",light.getScaling(frame));
info("Ambient: ", light.Ambient(frame));
info("Color: ", light.Color(frame));
}

Sometimes it runs, sometimes with error messages...

best regards, nice day, FrankyGTH

evenflcw
01-28-2009, 10:32 AM
Where is the value to the frame variable initialized (ie. assigned a value)? Assign it a value of 0.0 for frame 0.

You should perhaps change the variable name as, according to the docs, these methods want a time value (ie. in seconds!; =frame/fps), not a frame value (=time*fps).

EDIT:
There are two other errors aswell but you'll find them yourself.

HOT TIP!
Add the line:

debug();

at the top of the script (inside the { } naturally). This will open up a debugger window when you run the script and let you execute it one line at a time. Press F10 to step one line. You'll be able to watch how any variables change as the script is executing. It is a gem of a tool. (check menus for other hotkeys)

FrankyGTH
01-28-2009, 01:50 PM
hi dan:) thank you for the useful infos... I like it!

I have the script from the LSscriptUserGuide ;) haven't thought it's not running in this way...

I need help :-)
don't know how to handle time and frame values... I must see it, then I can understand it, there's missing a lot of LW scripts to understand the code structure, I am learning better with existing examples they are running! ;)

@version 2.2
@warnings
@name "LightsTest_FB"
generic

//Set Globals
frame = 0.0;
time = frame/fps;

{
light = Light();

var time, frame;
// time = 1/24

debug();

// Display some Data Members.
info("Name: ", light.name);
info("Type: ", light.type);

//Display some Methods.
info("Position: ",light.getPosition(time));
info("Rotation: ",light.getRotation(time+1.0).h);
info("Scaling: ",light.getScaling(time));
info("Ambient: ", light.Ambient(time));
info("Color: ", light.Color(time));
}

perhaps you can help so I can see the light in my head :-)
don't forget I am a newbie with LW scripting...

good evening, FrankyGTH

evenflcw
01-28-2009, 07:32 PM
The currenttime can be gotten from the Scene Object agent... most information can be gotten from one object agent or another. Check the Reference Manual for all object agents and what methods and members they provides you with. Once you've gotten through the User Manual and all the basic syntax stuff, you'll mainly be using the Reference Manual (and other sources completing it; if you can't remember it all).

To get the current time then. "Request" a scene object agent.

scene = Scene();

Then just call any method or read a member. Use it directly or assign it to a variable.

time = scene.currenttime;

or short version

time = Scene().currenttime;

(Compare this to how you got the light information)

Hopper
01-28-2009, 09:19 PM
Not the official documentation, but MUCH better:
http://www.mikegreen.name/Lscript/Lscript%20Index.html
Oh dude... wtf ... where did this come from? Oh MAN that would have helped about a month ago. Someone needs to sticky the hell out of that and put it in the LScript forum. (uhh.. or is it already .. I was too lazy to look).

But seriously... thanks Matt! That's an awesome resource.

FrankyGTH
01-30-2009, 02:24 AM
dear dan, hopper, matt :-) good morning! Coming back from work and have found a script with scene-obj-agent, thank you for this important advice.

Now I can imagine what the script needs...

Work in Progress, must laugh, I see a light at the horizont and make the script in the next days so it will run :)

found this one and think it's ok for the script:

scene = Scene();
cur_time = scene.currenttime;
cur_frame = cur_time * scene.fps;

and the request:

reqbegin("Frankys Light Editor");
reqsize(375,115);

c0 = ctlpercent("Light Intensity",1);
ctlposition(c0,10,10);

c1 = ctlrgb("Light Color", <0, 0, 0>);
ctlposition(c1,10,35);

after building that structures for my lighst I will ask here somebody again, if I have problems with the script language and the syntax...

btw: the "Context" script editor is GREAT ! :-))) and I have downloaded the syntax highlightings from here :

http://www.mikegreen.name/Files/CL.zip

perhaps you can use it too if you don't know it ! :)

so long, nice day for you and day by day I see more knowledge about lscripts and I will manage it to build the script, I am sure...

ciao, best regards, FrankyGTH
ps: the lightwave script editor isn't so bad, but needs to get updated, why newtek didn't make it??? or perhaps some lightwave developer can do that???

Matt
01-30-2009, 04:52 AM
My version of the Context Highlighters for .ls and .lws

adamredwoods
01-30-2009, 11:34 AM
I thought LSC was bytecode for the lscript, and therefore would run faster. maybe a test would help.
Anyone have a stopwatch, preferably one with a second hand?

FrankyGTH
04-07-2009, 02:03 PM
hi again:)

little question again how to handle or use the "ctl" commands...

I have tried to changed / add some ctl... into (see the last line) ... for eg ctlpolygon, but with "context" script editor this one doesn't show a blue text type (so I can think it's not ok..) but it run's with the three lines before :)... so I would like to know what commands are possible with "ctl"... ??? perhaps this question isn't quite new here...

does any list existing how to use this commands??? Sorry, but I haven't found anything...
I am learning the best way to study lw scripts with changing existing (running!!!) scripts and making experiments... :)

...code part--------
c[1] = ctlsurface("Break Surface",set[gsurf]);
c[2] = ctlinteger("Iterations",set[giter]);
c[3] = ctlcheckbox("Distribute",set[gdist]);
c[4] = ctlchoice("Break Type",set[gtype],@"Curved","Straight"@);
c[5] = ctlpolygon("Polygonal",set[gpoly]);
...code part end --------

best regards, I have to learn a lot with a programming language at the moment (school) and after it I can write some lw scripts, so god will :D must laugh...

ciao and servus, FrankyGTH - good evening all :)

evenflcw
04-07-2009, 02:17 PM
ctlpolygon()? Never heard of. All the available controls (and what their functions names are and what arguments they take) can be found in the LScript docs. You can download the docs from the developer section of Lightwaves homepage.

You can't just paste "ctl" infront of any word you like!?

FrankyGTH
04-08-2009, 01:39 AM
;) yes, thank you... dan !

you are right: "All the available controls (and what their functions names are and what arguments they take) can be found in the LScript docs..."

I have found it again, deleted the docs on my old machine and have had a newly look at the docs, but for me it's a general problem to found special help theme or command I know it from programming script editors they help for example with a "F1" button :) you click on the coloured command word and press "F1" to get a closer information about the "controls" of the application... would be a nice gift for lightwave programming guys/girls here, isn't it???

"ctlpolygon()" doesn't exist, don't worry... :D it was just an example to test the context editor and clear my thoughts about the control commands... ;)

one pity more is that the most script example of ls script documentation doesn't run at all... for a lw script beginner not very useful ;)... that's my personal opinion...

have a nice day, thank you, more will come, when I am ready with my first script :)

ciao, FrankyGTH

ps: show you one example of the lightwave script documentation...

-----------------------------
generic
{
reqbegin("Testing Idle");
c1 = ctlnumber("Number",1.0);
reqpost("idleTest"); // called at 500-millisecond
// intervals.
reqend();
}
color = <0,255 * .5,255 * .75>;
idleTest
{
drawline(color,0,2,100,2);

color.x += 5;
color.y += 5;
color.z += 5;
if(color.x > 255) color.x = 0;
if(color.y > 255) color.y = 0;
if(color.z > 255) color.z = 0;
}
----------------------------------
it doesn't work... so I need to ask here ... sorry... :)

evenflcw
04-08-2009, 05:25 AM
Works for me.

I copied it from your post verbatim. Except that I added some headers. I guess maybe you should Use the LScript Editor for starters. It has templates for all the different script types and the Check Syntax command.

(Thats a Layout script btw)

FrankyGTH
04-08-2009, 12:40 PM
Hi dan :)

thank you, your layout script example I have needed ! ;) good to see it works!

...and my script works fine now... and I have built a new little one, you can see... changed things, I am proud of it, it's just a little thing but "mine"... So I have an entry to this world and have understood three, four things to build a panel script layout! :D more to come, I promise it... see my attachment ... the colour lines and the little box in my script is changing without any input ;) - by the way: how can I set the "thickness" of a line???

best regards, FrankyGTH
"welcome to the pleasuredome"

evenflcw
04-08-2009, 04:59 PM
I haven't ever drawn within panels. Unless you are building some very nifty interfaces there is seldom need to. I usually try to get away with as few controls as possible.

If you don't know if there is a function or know for a fact there isn't then obviously you need to make do with what you got/know. Drawing thicker lines can be done by drawing the same line multiple times, each time with a slight offset or by dotting out tiny squares or circles at a regular offset along a distance. Create your own function for that if you need it.

Keep at it.