generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Now, on to the next issue

Previous Thread :: Next Thread 
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 09:23 AM
Since


local function clicked(num)
Instance.new("Hint", game.Workspace).Text = "clicked "..num
chosen = GUI[num].Text
end


is it's own function, I can't return chosen from it, it will just return to the PlayerList function, instead of the MouseButton1Down.

And I can't


--GUI:TweenPosition(UDim2.new(0, -320, 0.5, -125), "Out", "Linear", 0.5, false)
--return chosen


at the end of PlayerList, because it would head off right away and return a nil value, since it has no way of telling when the player has clicked a button.

So... something like



local function clicked(num)
Instance.new("Hint", game.Workspace).Text = "clicked "..num
chosen = GUI[num].Text
cango = true
end

repeat wait() until cango == true
GUI:TweenPosition(UDim2.new(0, -320, 0.5, -125), "Out", "Linear", 0.5, false)
return chosen


?
Report Abuse
SN0X is not online. SN0X
Joined: 24 Oct 2011
Total Posts: 7277
23 Jul 2013 09:24 AM
what are you talking about, where is this variable chosen and what is it

AW MAN THIS ISN'T WHERE I PARKED MY CAR
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 09:25 AM
variable chosen is undefined at the top of function Playerlist(). I define it in local function clicked, then I need to pass it on to the original MouseButton1Down function.
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 09:27 AM
And then there's the issue of

script.Parent.AdminGUI.VIPButton.MouseButton1Down:connect(function()
local c = PlayerList(false, false, false)
if c == nil then return end
local chosen = game.Players.c

Which needs to wait for function PlayerList to happen. But it has no way of doing that? Is there like a

repeat wait() until returned

or something?
Report Abuse
juzzbyXfalcon is not online. juzzbyXfalcon
Joined: 02 Feb 2011
Total Posts: 1311
23 Jul 2013 09:33 AM
start with

chosen = nil

at the top of the script, Idk, but I just think that will work better. Anyway, explain the use of

local function clicked(num)

and then I mean the "local" part. I don't know the difference between a local function and a function, can't find it either.

-Believe and you will achieve-
Report Abuse
darthpyro is not online. darthpyro
Joined: 18 Aug 2009
Total Posts: 3569
23 Jul 2013 09:34 AM
Does a local function even exist? I'm sure it wouldn't hurt anything, but..
Report Abuse
darthpyro is not online. darthpyro
Joined: 18 Aug 2009
Total Posts: 3569
23 Jul 2013 09:34 AM
Does a local function even exist? I'm sure it wouldn't hurt anything, but..

Someone here test that?
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
23 Jul 2013 09:35 AM
functions can be local just like any other variable.
As for OP, what are you trying to do exactly?
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 09:36 AM
@darth

woh nice post lag



Not sure if it does anything or not. Certainly doesn't seem to be hurting anything?

Also, the reason I'm returning chosen as nil is I need some way for


script.Parent.AdminGUI.VIPButton.MouseButton1Down:connect(function()
local c = PlayerList(false, false, false)
if c == nil then return end


To know when someone has pressed cancel, and end the function right there and then.
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 09:38 AM
@blocco,

function PlayerList(listAdmin, listVIP, listSelf) looks through all the games players. Makes sure that if listAdmin is off, it doesn't grab an admin, etc. Adds those names to buttons in a GUI. Tweens the GUI on to the screen and waits for a button press. Returns the text on the button pressed, so that players can easily select names from a list.

Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
23 Jul 2013 09:40 AM
It seems like you're doing it like a prompt. Are you sure that that is how you want to handle this?
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 09:41 AM
It seems either that or they type a name in. And typing is no fun.
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 09:44 AM
The idea is, you click a button, and you either select the name of a player in the game, or you click cancel.
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
23 Jul 2013 09:49 AM
Why not have a variable shared by whatever scopes need it that gets changed when you select a name?
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 09:54 AM
script.Parent.AdminGUI.VIPButton.MouseButton1Down:connect(function()
local c = PlayerList(false, false, false)
if c == nil then return end
local chosen = game.Players.c


But then how would that wait until we have either
1. pressed cancel
2. pressed a name

?
Report Abuse
juzzbyXfalcon is not online. juzzbyXfalcon
Joined: 02 Feb 2011
Total Posts: 1311
23 Jul 2013 09:57 AM
For the record, when you when you have a table with

for i = 1,#blahblah do

can you use the i again for another table? Because I always use different letters throughout my script.

-Believe and you will achieve-
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
23 Jul 2013 09:58 AM
You don't have to yield; just don't do anything if the person has not selected a name, or tween the GUI off if he pressed cancel.
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 09:59 AM
But would it not build up over time, (possibly) causing lag if they're all waiting for (lets say) variable target to change?
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
23 Jul 2013 10:01 AM
Why would you wait for it? Just use events and callbacks.
Report Abuse
juzzbyXfalcon is not online. juzzbyXfalcon
Joined: 02 Feb 2011
Total Posts: 1311
23 Jul 2013 10:02 AM
No, it would only cause lag if you'd use something stupid like this:

while true do
wait()
if not target then
dostuff()
end
end

-Believe and you will achieve-
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 10:04 AM
Hmm. I've actually never heard of callbacks, lol. Looks good by what the wiki says on it. But do you have an example? :P
Report Abuse
juzzbyXfalcon is not online. juzzbyXfalcon
Joined: 02 Feb 2011
Total Posts: 1311
23 Jul 2013 10:05 AM
Changed some things in your script, while reading through.

function PlayerList(listAdmin, listVIP, listSelf)
local GUI = script.Parent.Playerlist
local players = game.Players:GetChildren()
local people = {}
local GUIPos = 1
local chosen = nil --changed

for i = 1, #players do
local removed = false
table.insert(people, players[i].Name)
if (listAdmin == true) or (removed == true) or (players[i].Admin == true) then --changed
table.remove(people)
removed = true
end
end
if #people < 1 then
script.Parent.Alerts.Alert_0.TextLabel.Text = "No valid players to select!"
script.Parent.Alerts.Alert_0:TweenPosition(UDim2.new(0.5, -250, 0, 150), "Out", "Bounce", 2, false)
wait(3.5)
script.Parent.Alerts.Alert_0:TweenPosition(UDim2.new(0.5, -250, 0, -50), "Out", "Quint", 0.75, false)
return nil
end
for i = 1, #people do
GUI[GUIPos].Text = people[i]
GUIPos = GUIPos + 1
end
local c = GUI:GetChildren()
for i = 1, #c do
if i > #people then
c[i].Visible = false
end
end
GUI.Cancel.Visible = true
GUI.Cancel.Text = "Cancel"
GUI:TweenPosition(UDim2.new(0.5, -160, 0.5, -125), "Out", "Linear", 1, false)
wait(1)
function clicked(num)
Instance.new("Hint", game.Workspace).Text = "clicked "..num
--chosen = GUI[num].Text
GUI:TweenPosition(UDim2.new(0, -320, 0.5, -125), "Out", "Linear", 0.5, false)
return GUI[num].Text --chosen
end
GUI["1"].MouseButton1Down:connect(function( clicked(1) end)) --changed?
GUI["2"].MouseButton1Down:connect(function( clicked(2) end))
GUI["3"].MouseButton1Down:connect(function( clicked(3) end))
GUI["4"].MouseButton1Down:connect(function( clicked(4) end))
GUI["5"].MouseButton1Down:connect(function( clicked(5) end))
GUI["6"].MouseButton1Down:connect(function( clicked(6) end))
GUI["7"].MouseButton1Down:connect(function( clicked(7) end))
GUI["8"].MouseButton1Down:connect(function( clicked(8) end))
GUI["9"].MouseButton1Down:connect(function( clicked(9) end))
GUI["10"].MouseButton1Down:connect(function( clicked(10) end))
GUI["11"].MouseButton1Down:connect(function( clicked(11) end))
GUI["12"].MouseButton1Down:connect(function( clicked(12) end))
GUI["13"].MouseButton1Down:connect(function( clicked(13) end))
GUI["14"].MouseButton1Down:connect(function( clicked(14) end))
GUI["15"].MouseButton1Down:connect(function( clicked(15) end))
GUI["16"].MouseButton1Down:connect(function( clicked(16) end))
GUI["17"].MouseButton1Down:connect(function( clicked(17) end))
GUI["18"].MouseButton1Down:connect(function( clicked(18) end))
GUI["19"].MouseButton1Down:connect(function( clicked(19) end))
GUI["20"].MouseButton1Down:connect(function( clicked(20) end)))
GUI["Cancel"].MouseButton1Down:connect(function()
Instance.new("Hint", game.Workspace).Text = "pressed cancel"
GUI:TweenPosition(UDim2.new(0, -320, 0.5, -125), "Out", "Linear", 0.5, false)
return nil
end)
--GUI:TweenPosition(UDim2.new(0, -320, 0.5, -125), "Out", "Linear", 0.5, false)
--return chosen
end

-Believe and you will achieve-
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 10:09 AM
"if (listAdmin == true) or (removed == true) or (players[i].Admin == true) then --changed"

You can't change this. I'm not even sure what you've done here. But it can't work like this. If I want VIPs listed but Admins not, I need it to check them seperately. Also, I'm fairly certain you've inverted the bool values.

if (listAdmin == false) and (removed == false) and (players[i].Admin == true) then
table.remove(people)
removed = true
end
if (listVIP == false) and (removed == false) and (players[i].VIP == true) then
table.remove(people)
removed = true
end
if (listSelf == false) and (removed == false) and (players[i] == player) then
table.remove(people)
removed = true
end
end


Works just fine. But thanks. As for nil, I don't really think it necessary?
Report Abuse
juzzbyXfalcon is not online. juzzbyXfalcon
Joined: 02 Feb 2011
Total Posts: 1311
23 Jul 2013 10:14 AM
Oh, wow, wait. I only now see that the variables are totally different the three times, lol.

That's what you get for debugging someone else's script. :p

-Believe and you will achieve-
Report Abuse
Inviting is not online. Inviting
Joined: 05 Apr 2011
Total Posts: 99
23 Jul 2013 10:17 AM
@blocco,

on the wiki...

local func = Instance.new('BindableFunction', script.Parent)

Is this necessary for callback? Does it need to be the same? What do I change?

func.OnInvoke = PlayerList(false, false, false)

?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image