Ojia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 650 |
|
|
| 06 Dec 2014 09:27 AM |
Here are some more scripting questions I have, answer if you would like.
1. What would be considered the game 'client' (I might be late for this but I'm still wondering)
2. How would you use for i,v in pairs/iparis() do correctly? (Ex. for i,v in pairs/ipairs(stuff) do)
3. What does changing locals to false/true mean? (ex. local isOwner = false)
4. Are boolvalues the same as mentioned before or different?
5. When would you use something else besides a number in for, (Ex. for i = 1,count do) and what does # mean? (Ex. for i = 1,#count do)
6. What does coroutine mean/do? (Ex in chat voice: coroutine.resume(coroutine.create(function()) Thank you for your time reading, if I have more I'll come back, If you have answered thank you so much. |
|
|
| Report Abuse |
|
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
|
| 06 Dec 2014 09:41 AM |
2. --This will scan threw everything that in in workspace. --It will only detect the items in workspace tho, like if you where to have "workspace < model < part" it'll only get the model seeing that that's the thing that's in workspace.
--You can use it like this below this will find any Part in workspace and count it and then print the total parts as long as every part is in workspace.
total = 0 for i,v in pairs(workspace:GetChildren()) do if(v:IsA("Part")) then total = total + 1 end end print("Total parts in workspace "..total)
3. lets say you want to be able to turn something off and on youd do this...
on = false --We'll make false be off and true on. if(on == false) then print("it's off") elseif(on == true) print("it's on") end
you could really use anything does not have to be true or false it coud be 1 or 2, y or n. it really doent matter.
5. i assume is for a table.
lets say you have a table and wanted to get the total number of stuff you have in that table youd do
table = {"sfffv","ferferf","erfesrf"}
print(#table) --it'll print 3
-Codys4x4 - Send me a trade. |
|
|
| Report Abuse |
|
|
Ojia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 650 |
|
|
| 06 Dec 2014 10:09 AM |
Ok, so in pairs is basically used to scan stuff for things? That would make sense, but would it be the same like this local stuff = {Player = true} for i,v in pairs(stuff) do
What would that do basically? |
|
|
| Report Abuse |
|
|
Ojia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 650 |
|
|
| 06 Dec 2014 10:13 AM |
| Ohhhhhh I see what # does now, it takes the i out of it, perfect for math.random. |
|
|
| Report Abuse |
|
|
| |
|
Ojia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 650 |
|
|
| 06 Dec 2014 12:40 PM |
| Um can someone please tell me what the rest means/does please? |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 12:45 PM |
coroutines = threading rel8ted
lets say we have two loops
--loop A while wait(1) do print'A' end
--loop B while wait(1) do print'B' end
now, A never stops running, right? this is what we'd use coroutines for two loops running at the same time
also you'll find delay() and spawn() very useful
|
|
|
| Report Abuse |
|
|
Ojia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 650 |
|
|
| 06 Dec 2014 05:00 PM |
| So they just make two loops run at once? |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 05:08 PM |
wellllll it's an application of it
it's all about threading
delay() is one of the most useful things there is |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 05:10 PM |
I actually don't use specifically coroutines at all. Uglier syntax imo.
If I want to do this:
delay(3, function() game.Players.PlayerAdded:connect(function(player) end)
end)
print 'This printed.'
Delay's first argument is how much to wait in seconds before executing the function.
Now, if you run that in the command bar, you'll notice This printed. printed immediately.
Now, using wait() would cause the whole script to wait 3 seconds. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Dec 2014 05:12 PM |
Basically. I'll try to answer them all to the best of my ability:
'1. What would be considered the game 'client' (I might be late for this but I'm still wondering)' RobloxPlayerBeta
'2. How would you use for i,v in pairs/iparis() do correctly? (Ex. for i,v in pairs/ipairs(stuff) do)' Pairs is an iterator that uses the "next" function to get keys and values of a table. Ipairs is an iterator that uses a counter to get keys and values of a table.
'3. What does changing locals to false/true mean? (ex. local isOwner = false)' It just changes the value, where true is basically "yes" and false is basically "no".
'4. Are boolvalues the same as mentioned before or different?' BoolValues are Roblox instances that have a Value property that take a bool.
'5. When would you use something else besides a number in for, (Ex. for i = 1,count do) and what does # mean? (Ex. for i = 1,#count do)' As said above, it gets the length of a table or string.
'6. What does coroutine mean/do? (Ex in chat voice: coroutine.resume(coroutine.create(function())' It sort of acts like a thread in which you can run two things at once. Except that coroutines are not actually threads, so in reality only run one thing at once but is suspended with yielding which allows other coroutines to resume.
|
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 05:12 PM |
I'm mostly sure but the Wiki will be certain.
Spawn is, I know that. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Dec 2014 05:12 PM |
| Yeah, the Delay and Spawn function are Roblox-specific. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 06 Dec 2014 05:15 PM |
| I wouldn't use them then, unless you want them to do whatever it is they were made to do. |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 05:17 PM |
"I wouldn't use them then, unless you want them to do whatever it is they were made to do."
I have a function which runs on delay 0 that changes lighting's TimeOfDay to the real time in my main server side script, along with the rest of the place's main logic.
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Dec 2014 05:18 PM |
| IIRC Spawn (and/or Delay) create real threads as opposed to coroutines. I could be wrong, I don't remember where I read that. |
|
|
| Report Abuse |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 06 Dec 2014 05:22 PM |
"I have a function which runs on delay 0 that changes lighting's TimeOfDay to the real time in my main server side script, along with the rest of the place's main logic." This could be done with a coroutine, and follow the rest of the Lua world.
"IIRC Spawn (and/or Delay) create real threads as opposed to coroutines. I could be wrong, I don't remember where I read that." I knew coroutines only simulated multithreading but I didn't know Spawn and Delay created real threads. In the end, is there any difference? |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 05:23 PM |
"This could be done with a coroutine, and follow the rest of the Lua world."
why should i NOT have better looking code
delay(0, function() end)
beautiful |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Dec 2014 05:33 PM |
If you are going to have a 0, just use spawn.
'I knew coroutines only simulated multithreading but I didn't know Spawn and Delay created real threads. In the end, is there any difference?' If you have a multi-core CPU. |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 05:36 PM |
i know i can do spawn()
but i use delay always in case i want to change it later on
HOWS THAT FOR EFFICENCY..... |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Dec 2014 05:37 PM |
| It's bad, why are you even doing it in a new thread anyways? |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 05:38 PM |
i use a lot of loops and i prefer to have my layout in scripting be:
-ServerScriptService ---ServerMain
-StarterGui ---ClientMain
1 script
|
|
|
| Report Abuse |
|
|