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: Detecting Table Stuff

Previous Thread :: Next Thread 
neff111 is not online. neff111
Joined: 15 Nov 2010
Total Posts: 65
24 Jun 2014 09:06 PM
I need help detecting if a certain thing is already in a table.

This is what I have:


PlayerShip = {}

Ship=Player:GetMouse().Target.Parent
for iiii = 0,#PlayerShip+1 do
print(PlayerShip[iiii],Ship.Name) -- This is just so I can probly find the problem
if Ship~=PlayerShip[iiii] then
table.insert(PlayerShip,Ship)
end
end


I have no good idea what the problem is. Does anyone have advise?
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
24 Jun 2014 09:09 PM
PlayerShip = {}
Ship = Player:GetMouse().Target.Parent

for i,v in pairs(PlayerShip) do
if Ship ~= v then
table.insert(PlayerShip,Ship)
end end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Uhm.. you're entering the value into the table IF it's close enough to one that's already in the table. What's the point of this? Cleaned it up for you.
Report Abuse
neff111 is not online. neff111
Joined: 15 Nov 2010
Total Posts: 65
24 Jun 2014 09:12 PM
Rocket Science :3
Jk

Im trying to create a style of game where you controll a fleet of space ships, but I was having the problem of accedently selecting a ship more than once and breaking the script :I
Report Abuse
neff111 is not online. neff111
Joined: 15 Nov 2010
Total Posts: 65
24 Jun 2014 09:12 PM
Dubble Post, Sorry
Thx
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
24 Jun 2014 09:16 PM
You could make the ship a key:

local t = {}
local n = 0

function deselect()
t = {}
n = 0
end

function select(object)
n = n + 1
t[object] = n
end


Now you select an object twice and it wont matter, and you can use next to iterate through the table.
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