View unanswered posts | View active topics It is currently Thu, January 18th, 2018, 16:10



Reply to topic  [ 7 posts ] 
Script bin 
Author Message
Global Moderator
User avatar

Posts: 650
BL Name: McTwist
BL ID: 9845
Post Script bin
This topic is for sharing scripts with the rest of the community. It may be a small piece of code or a larger one. Everything you post here will be public domain.

Now bring in your scripts!

[size=75][color=#007FFF]Stickied and fancied up.
-Demian[/color][/size]

_________________
[img]http://img115.imageshack.us/img115/2213/logoqn0zp3.png[/img]


Fri, December 17th, 2010, 00:37
Profile
Global Moderator
User avatar

Posts: 650
BL Name: McTwist
BL ID: 9845
Post Re: Script bin
I'll start now, and bring in more myself later:

[code]function makeBar(%num, %max, %amount)
{
%n = mCeil((%num / %max) * %amount);
%str = "";
for (%i = 0; %i < %amount; %i++)
%str = %str @ (%i < %n ? "1" : "0");
return %str;
}[/code]
If you do this:
[code]makeBar(250, 500, 6);[/code]
It will return:
[code]111000[/code]
This can be used for loading bars. Alteration or modification is possible and easy to do.

_________________
[img]http://img115.imageshack.us/img115/2213/logoqn0zp3.png[/img]


Fri, December 17th, 2010, 00:39
Profile
Global Moderator
User avatar

Posts: 650
BL Name: McTwist
BL ID: 9845
Post Re: Script bin
And continues with this:
[code]function loopNameObject(%name, %func)
{
%temp = "__TEMP_NAME_";
for (%i = 0; isObject(%name); %i++)
{
call(%name, %func);
%name.setName(%temp @ %i);
}
for (%n = %i; %n >= 0; %n--)
{
%na = %temp @ %n;
%na.setName(%name);
}
}[/code]
It loops through all objects with the same name. Good when managing large group of objects with the same name.
[code]loopNameObject(_brickName, doEventFunction);[/code]
This will call doEventFunction on all objects that is named _brickName. Various checks can be made within doEventFunction if required.

_________________
[img]http://img115.imageshack.us/img115/2213/logoqn0zp3.png[/img]


Fri, December 17th, 2010, 00:43
Profile
User avatar

Posts: 2
BL Name: Flaw
BL ID: 2107
Post Re: Script bin
Is this restricted to TorqueScript? If not..
[code]
import random
def getRandom(min, max):
return random.random() * max + min
[/code]

_________________
~ BL_ID: 2107


Thu, March 3rd, 2011, 13:52
Profile
Global Moderator
User avatar

Posts: 650
BL Name: McTwist
BL ID: 9845
Post Re: Script bin
Yes it is. Is that Lua?

_________________
[img]http://img115.imageshack.us/img115/2213/logoqn0zp3.png[/img]


Sat, March 5th, 2011, 10:43
Profile

Posts: 1
BL Name: DontCare4Free
BL ID: 23618
Post Re: Script bin
No, Python.
Lua's syntax is more VB-ish.


Sun, March 20th, 2011, 13:32
Profile
Global Moderator
User avatar

Posts: 650
BL Name: McTwist
BL ID: 9845
Post Re: Script bin
Oh yes! You're right. I've been working with Lua before, but never with Python.

_________________
[img]http://img115.imageshack.us/img115/2213/logoqn0zp3.png[/img]


Mon, March 21st, 2011, 13:30
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.