![]() |
Question about checking an array.
So i'm learning about how all this works. and ive stumbled across a problem.
lets say i'm storing a variable in an array, and i want the script to check to see if they already have that variable in the array before adding it again. (to prevent duplicates) i've tried a few things such as using if("varthing": in client.varname) or whatever and strcontains wasnt the answer either. what should i be using to check? |
PHP Code:
Correct: PHP Code:
PHP Code:
|
Thanks again, cbk! :D
|
You can also compare array lists
HTML Code:
temp.a_0 = {"list", "lista"}; |
Just a note on the @temp.some_array syntax... when @ casts the array to a string, it will do a loop internally. This means that the @ operation on an array will take longer as the size of the array gets bigger.
Given the arrays N and M, it will take N.size() operations, then M.size() operations to convert them both to strings. Then, to actually compare the two strings, it will take min(StringN.length(), StringM.length()) operations at worst (if they aren't equal). So, that method of checking equality actually takes more operations than a GS2 loop. However, since it is the engine doing the conversion to a string and the string equality check, it will be faster than doing a loop in GS2 (probably). The one case where a GS2 loop would be better is if the arrays are really big, but differ near the beginning. This would be faster because you could break the loop on the first inequality. Converting the array to a string wouldn't be able to do that, which could be deadly on a really big array. |
So before you do an internal loop, check with the size of the array and the length before comparing them!
(Thanks @ WD) |
Alright I have a semi-related problem so I'll post it here instead of creating a new topic.
Working on a buff/debuff system I've decided to store the data I need a certain way: e.g.: client.buffs = "Slow:60:-50","Bleed:25:100" the 60 on the slow debuff represents the timer. so does the 25 on bleed. now here's my problem: I seem unable to set the values representing the time left to another value. I had already changed my format thinking it was that i had all of the data for each buff as a string thinking maybe you can only change nonstring/nonquoted numbers. but i've changed it back since that didnt work. This is the function I'm currently using to lower this value: PHP Code:
|
Try multi-dimensional arrays instead.
PHP Code:
PHP Code:
PHP Code:
|
Thanks I think i got it now :D
|
All times are GMT +2. The time now is 12:00 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.