|
| 21 Nov 2012 05:43 PM |
Hi everybody,
newbie to Roblox here (but not to scripting/programming, with everything from c-shells to python passing through tcl, mel, javascript, java, the occasional C++ and a few esoteric things such as xslt!).
Been toying around with roblox for a few days now, letting a few ideas slosh around in my head to give them some limited clarity. I have a few sparse questions to ask.
1) I'm not quite clear when scripts execute. It appears that in Roblox Studio they execute when you paste them in the workspace. It'd be nice if they did when I press the play button or some time afterward. Any way to do this?
2) Are multiple scripts intended for continuous execution running interleaved through (lua/coroutines-based) cooperative multithreading or are they running in parallel through OS threading?
3) Of course when writing scripts for continuous execution (say, a traffic manager, controlling a bunch of constantly moving npc cars) one better let them sleep now and then to avoid hoarding the CPU. The question is though: how can I decide how often and for how long to let them sleep? I.e. is server physics running on a separate thread anyway and my script only compete for server resources with each other?
4) Any chance to anchor a part A to a part B in way that if I resize the latter the former will remain attached in an intuitive fashion? I.e. stack two cubes and change their surfaces to universal types to keep them together. Then, resize upward (i.e. myPartB.Size =Vector.new(1,2,1)) the lower one. I'd expect it to push myPartA higher up, instead it is first translated -above- myPartA and then resized. Alternatively, think of an inverted L made of cubes. If I resize vertically the vertical segment I'd like the horizontal segment to reposition accordingly. Notice that grouping wouldn't do because it would scale the thickness of the horizontal segment. Of course I could do all sorts of tricks with CFrame but I wonder if there are simple ways that I've overlooked.
Thanks for your help!
Manu |
|
|
| Report Abuse |
|
|
nrscsy
|
  |
| Joined: 09 Nov 2012 |
| Total Posts: 465 |
|
|
| 21 Nov 2012 05:48 PM |
1) If the client is not running, no script will run until you hit the Play button.
2) Put simply, several scripts are there for easier channeling. You can make all code in a single script. LocalScripts do not behave like normal scripts, though. Look up documentation on them in the wiki.
3) There is no way to know this since you can't get the user's system specifications. Simply predict and use coroutines to yield when you find it necessary.
4) No simpler ways as far as I know. |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2012 05:50 PM |
Oh, one more question:
5) Are there lighter way to associate a value with a Part than creating a *Value node? I guess I could create a table, something like _G[myPart]. Any other way? |
|
|
| Report Abuse |
|
|
nrscsy
|
  |
| Joined: 09 Nov 2012 |
| Total Posts: 465 |
|
|
| 21 Nov 2012 05:52 PM |
| 5) Didn't quite understand that. Variables don't clog up much space. Adding variables to a table for organization is not something I like to do. |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2012 05:59 PM |
Well, say you have 10K cubes. And each needs to store some values. One way to do it is to add a bunch of NumberValue nodes under each which can then be accessed via myCube3986.myAppropriatelyNamedValue. Great, it works.
I do wonder however if holding a table mapping objects to key/value pairs would be lighter.
Manu |
|
|
| Report Abuse |
|
|
nrscsy
|
  |
| Joined: 09 Nov 2012 |
| Total Posts: 465 |
|
|
| 21 Nov 2012 06:01 PM |
| Sorry, I don't know how to create psuedo-objects that act as values. |
|
|
| Report Abuse |
|
|
|
| 22 Nov 2012 06:48 AM |
| You mean you don't know how to use classes such as BoolValue and NumberValue or you don't know how to deal with lua tables and metatables? |
|
|
| Report Abuse |
|
|
|
| 22 Nov 2012 07:38 AM |
To associate an object with a variable we don't need to number values, rename the object something that no other object is named, such as Part123. Then in the script write
VariableA = game.Workspace.Part123
I believe that's what your asking for? |
|
|
| Report Abuse |
|
|
|
| 22 Nov 2012 09:10 AM |
Yes it is fun, to have a bunch of pre-made grphics and a premade space to push things around in.
I'm making a pair of hockey skates out of the pre-made Skateboard for eg.
If u want to program, together, PM, me. Will make a hockey game. Check-out the game, Ledgens of Hockey to see what CAN be done with the objects already made, and little programming...
1) In Studio, goto Edit to Edit scripts. You can hit Play to Test, then hit reset. (For scripts not requireing Humanoid interaction)
Goto Build to Test scripts with your Character.
3) Wait is what you are looking for. There must be a wait in every script. Wait() waits for one frame, and if most of your scripts use this; your computer will chrash, or your Place will Lag-out. wait(.03) is aproximately the same thing as one frame; but not.
Wait(1). 1 second wait is much better, and as your scripts are mostly just setting things in motion, then letting the physics take over; doing calculations once every second is fine for your Main Script,, and gives your other scripts some quality time with the CPU.
You mostly just set-up a bunch of Interupts (called Events here) to do important stuff at critical times, then just sit-around and Wait.
4) No. I have found "building" things and resizing things on-the-fly, in a script not very succesful. Basically, build the heck out of something (make one a size bigger, if u will need one, later), build everything; stick it in a Model. Then swap Models in and out of the main view.
It's a great 3D graphics engine; a little buggy, but who doesn't have bugs? It doesn't break easily.
PM me for help with Humanoids; AI; Skateboard script; or Ray-casting.
GL, Brian
|
|
|
| Report Abuse |
|
|
|
| 22 Nov 2012 09:13 AM |
1) if you add a wait(seconds here) at the beginning of a script then the script will wait that long before executing.
|Paradoxical|
I shun thy heathen, dost thou not know that flames will devour thy mind? |
|
|
| Report Abuse |
|
|
|
| 22 Nov 2012 09:17 AM |
5) Yes, u don't have to use Object Values; think of them as a graphic Interface so that some-one else who uses your Script, later can easily set User Variables. You can just use variables in your script for non-User set values, and yes each "part" is already unique, and addressable at any time from any script. Change it's .Name property to make it even more unique; or it's color;
or use it's un-used Rotatioal Velocity to store some of your own values (If the Part is anchored it won't Rotate anyway, and will ignor the values). |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 22 Nov 2012 09:19 AM |
For your final question, it's really simple. You can create the object index in the global table.
local part1 = Workspace.Part1
_G[part1] = {part1.Transparency, part1.Name == "Hello" --[[A bool]]}
Such like that. You could also use a for loop to put them in there automatically instead of individually. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 27 Nov 2012 03:38 PM |
Hi everybody!
Sorry for the late answer. Taking care of a 20 months old full time doesn't leave much free time! Thank you all for your replies much appreciated. I'll see what I can concoct out of them!
Ciao!
Manu |
|
|
| Report Abuse |
|
|