I have several Lists. I want to keep PlayerLogins in one list at a time only. So when I add a PlayerLogin to one list(array) I want to remove it from all others.
just using List.remove gives "this value will be discarded" while compiling. Still seems to work but it interupts the compiling and I figure it might make the script really slow if it discards after several attempts to get and remove value.
So what I need some help with is to move a login from a list to a different while making sure that list is the only list that contain the login.
Example:
List A Superman,Hulk,Finn,Gir
List B Flash,Spiderman,Bender
List C Dr_Doom,Alex
Now I want to move Finn from list A to list B
So I add Finn to list B
Remove Finn from list A and C since I don't check if the list contains Finn and just want to make sure not to get duplicate.
Which is the best way to solve it?
Moving values between arrays
Moderator: English Moderator
Re: Moving values between arrays
if you are using php try:
array_pop
array_shift
array_pop
array_shift
TPS Gaseco - iPhone TM Remote Controller - GOS Coder
Re: Moving values between arrays
tryMuNgLo wrote:just using List.remove gives "this value will be discarded" while compiling. Still seems to work but it interupts the compiling and I figure it might make the script really slow if it discards after several attempts to get and remove value.
Code: Select all
declare Temp = Array.remove(Login);
(.remove() returns the removed value)
i would suggest a method like thisMuNgLo wrote:So what I need some help with is to move a login from a list to a different while making sure that list is the only list that contain the login.
Example:
List A Superman,Hulk,Finn,Gir
List B Flash,Spiderman,Bender
List C Dr_Doom,Alex
Now I want to move Finn from list A to list B
So I add Finn to list B
Remove Finn from list A and C since I don't check if the list contains Finn and just want to make sure not to get duplicate.
Which is the best way to solve it?
Code: Select all
Void AddToArray(Text _Login, Text[] _Array) {
declare Temp = Array1.remove(_Login);
Temp = Array2.remove(_Login);
Temp = Array3.remove(_Login);
_Array.add(_Login);
}
i'm not sure if there will be an error if you try to remove a value which isn't in an array! so you might want to test the existence of the value (i think there won't be an error, instead there will be Null returned, but you better try it yourself ^^)
Code: Select all
if (Array.exists(Login)) {
declare Temp = Array.remove(Login);
}
Last edited by steeffeen on 04 Mar 2013, 12:46, edited 1 time in total.
Re: Moving values between arrays
Removing a non-existing value shouldn't cause an error.
Who is online
Users browsing this forum: No registered users and 2 guests