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 » Scripters
Home Search
 

Re: Challenge - Prize [Scripters]

Previous Thread :: Next Thread 
HexC3D is not online. HexC3D
Joined: 30 Jun 2012
Total Posts: 10044
16 Sep 2015 02:35 PM
Since I'm back I'll like to host a challenge, a simple one[some parts to some people].

INDEX = {
0;
8;
2;
1;
}

Attribute those numbers to any of these following items first.

Objs = {
cntkillme;
eLunate;
Jarod;
analyze;
stealthking95;
};

This next phase is a little bit more. Now create function which both inputed the number or the values in the table "Objs" it retrieves and assigns the value/number to a new a value/number.

This is just some busy work and for other people to take as learning moment.
Winner will attain R$500
Report Abuse
HexC3D is not online. HexC3D
Joined: 30 Jun 2012
Total Posts: 10044
16 Sep 2015 02:36 PM
NewIndex = {
INDEX = {
0;
8;
2;
1;
7;
}

Use this new one instead the old index.
Report Abuse
InsaneDays is not online. InsaneDays
Joined: 28 Jan 2012
Total Posts: 762
16 Sep 2015 02:55 PM
So basically you got to assign INDEX to Objs and then change the values in Objs to a new value..?
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
16 Sep 2015 02:56 PM
It's really hard to understand what you're saying. So you want the function to retrieve a random pair, then swap the index with another pair?
Report Abuse
HexC3D is not online. HexC3D
Joined: 30 Jun 2012
Total Posts: 10044
16 Sep 2015 09:49 PM
No no. Be able to find the value or number by inputting the value or number.

This is just for fun.
Report Abuse
HexC3D is not online. HexC3D
Joined: 30 Jun 2012
Total Posts: 10044
16 Sep 2015 09:49 PM
Then be able to change the values/number bindings at will
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
16 Sep 2015 09:51 PM
What does that even mean? If you are able to find the value or number, then you already know the value or number. Did you mean like if given an index, find the value? Or if given a value, find the index?
Report Abuse
Botchan is not online. Botchan
Joined: 14 Jun 2015
Total Posts: 269
16 Sep 2015 09:51 PM
Sounds easy but I'm on mobile.

Basically, you want a dictionary which values are static.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Sep 2015 09:52 PM
where 0 points to the first element of Objs
8 points to the second element of Objs
(well, just runs through a function that gives you the index)
and so on?
Report Abuse
Botchan is not online. Botchan
Joined: 14 Jun 2015
Total Posts: 269
16 Sep 2015 09:53 PM
He's saying create a dictionary. Dictionaries are basically objects with values. That's how I would do it.

Then, make it so you can change the values the objects are assigned to freely in the script. However, you have to turn Obj into a dictionary.
Report Abuse
HexC3D is not online. HexC3D
Joined: 30 Jun 2012
Total Posts: 10044
16 Sep 2015 09:53 PM
Nono.

Randomly or Manually assign the Values with the index.

Like

eLunate = 0;
qq
and be able to fine elunates name or number even if you input it like this

Dostuffz(0) -- return elunate
Dostuffz(eLunate) -- returns 0

and be able to switch around the numbers to different values.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Sep 2015 09:54 PM
local omg = {
cntkillme = 0,
blah = 7
}

for key, value in next, omg do
omg[value] = key;
end

omg[7] = blah, omg.blah = 7
Report Abuse
HexC3D is not online. HexC3D
Joined: 30 Jun 2012
Total Posts: 10044
16 Sep 2015 09:55 PM
Botchan is right, it is a static dictionary that goes both ways.

But the def. you get the meaning vice-versa.
and be able to switch around values -- required.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Sep 2015 09:55 PM
The last line is not part of the code, oops.
Anyways you would just select a key and remove it and assign it to one of us (or the other way around like what i did, select a name and get a random key and remove them).
Report Abuse
HexC3D is not online. HexC3D
Joined: 30 Jun 2012
Total Posts: 10044
16 Sep 2015 09:56 PM
Yes, but it has use the table provided.
Report Abuse
HexC3D is not online. HexC3D
Joined: 30 Jun 2012
Total Posts: 10044
16 Sep 2015 09:58 PM
But you have to able to call out the both sides of the values.

The Value and the number must lead to one another.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Sep 2015 10:01 PM
INDEX = {
0;
8;
2;
1;
7;
}

Objs = {
cntkillme;
eLunate;
Jarod;
analyze;
stealthking95;
};


-- assign randoms --
local swog = {};
for key = 1, #Objs do
swog[Objs[key]] = table.remove(INDEX, math.random(#INDEX));
end
for key, value in next, swog do
swog[value] = key;
end

local function Dostuffz(key)
return swog[key];
end
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
16 Sep 2015 10:01 PM
And what if you have a key and value that are the same?
Report Abuse
Tynezz is not online. Tynezz
Joined: 28 Apr 2014
Total Posts: 4945
16 Sep 2015 10:07 PM
function swap(tab,value) for i,v in pairs(tab) do if i==value or v==value then return i==value and i or v end end end
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
16 Sep 2015 10:09 PM
^ You returned the wrong thing.
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
16 Sep 2015 10:09 PM
Didn't understand it so im not gonna do it
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Sep 2015 10:09 PM
If that happens, well then the answer would be the given input... So I don't see how that'll be a problem.
Report Abuse
Tynezz is not online. Tynezz
Joined: 28 Apr 2014
Total Posts: 4945
16 Sep 2015 10:13 PM
Yeah oops, just made it in the thread... I think this might be correct:

function swap(tab,value) for i,v in pairs(tab) do if i==value or v==value then return i==value and v or i end end end
Report Abuse
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
16 Sep 2015 10:28 PM
Like a dictionary?

Objs = {
[0] = cntkillme,
[8] = eLunate;
[2] = Jarod;
[1] = analyze;
[7] = stealthking95;
};

function changeTable(operation, index, value)
if operation == 'delete' or operation == 1 then
if index then
print("Deleted (" .. tostring(index) .. ", " .. tostring(Objs[index]) .. ") from the table.")
table.remove(Objs, index)
elseif value then
for i, v in next, Objs do
if v == value then
print("Deleted (" .. tostring(index) .. ", " .. tostring(Objs[index]) .. ") from the table.")
table.remove(Objs, i)
end
end
else
print("You need to specify an index or a value to use the delete operation.")
end
elseif operation == 'newValue' or operation == 2 then
if index and value then
if Objs[index] then
print("Replaced (" .. index .. ", " .. tostring(Objs[index]) .. ") with (" .. index .. ", " .. tostring(value) .. ")")
Objs[index] = value
else
table.insert(Objs, index, value)
end
if Objs[index] == nil or Objs[index] ~= value then
print("Error - Some error occurred while trying to do new value operation")
end
else
print("You need to specify both a new index number and the value to use the new index operation.")
end
elseif operation == 'newIndex' or operation == 3 then
if index and value then
for i, v in next, Objs do
if v == value then
if Objs[index] then
Objs[i] = Objs[index]
Objs[index] = value
print("Switched (" .. i .. ", " .. tostring(value) .. ") with (" .. index .. ", " .. Objs[i] .. ")")
else
table.insert(Objs, index, value)
table.remove(Objs, i)
print("Moved (" .. i .. ", " .. tostring(value) .. ") to (" .. index .. ", " .. tostring(value) .. ")")
end
end
end
if Objs[index] == nil or Objs[index] ~= value then
print("Error - either the value was not found or some error occurred while trying to do new index operation")
end
else
print("You need to specify both a new index number and the value to use the new index operation.")
end
end
if Objs[index] then
if value == nil then
Objs[index]
elseif
Objs[index] = value
end
end
end

So I haven't tested this because I don't have ROBLOX studio installed to test it with, I literally just wrote this in the little reply window on ROBLOX forums. xD But basically you have the dictionary defined in the beginning and you can call changeTable(operation, index, value) to edit the Objs table.

For the operation argument, you can pass in "delete" (or 1), "newValue" (or 2), or "newIndex" (or 3).

When using the delete operator, specify an index or a value. If you specify an index, it will delete that index. If it cannot find the index or you leave the argument empty, it will look for the value and delete the first one it finds instead.

For the newValue operator, specify an index and the value you want it to be.

For the newIndex operator, specify the value to replace the index of and it will give it the new index. If an index already exists with the new index, it will SWITCH the two values.

I swear, I hope this is what you wanted, that took some time. xD

-The [Guy]
Report Abuse
Tynezz is not online. Tynezz
Joined: 28 Apr 2014
Total Posts: 4945
16 Sep 2015 10:29 PM
^ whaa
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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