ID:175128
 
Is it possible to use the for loop to loop through the vars a mob has. Here is what I made but it dosn't work.

Lookatvars(mob/M in world)
for(var/mob/var/V in M)
for(V!=null||0)


Then how would I give the option to select a var that is more then 0 and alter its value.

Thank you for your time.
SSChicken wrote:
Is it possible to use the for loop to loop through the vars a mob has. Here is what I made but it dosn't work.

Lookatvars(mob/M in world)
for(var/mob/var/V in M)

"in M" is interpreted as "in M.contents", which is wrong. You just need to loop through var/V in M.vars.

for(V!=null||0)

What exactly were you hoping to accomplish with this line? The condition makes no sense, and putting it in a for statement makes even less.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
for(V!=null||0)

What exactly were you hoping to accomplish with this line? The condition makes no sense, and putting it in a for statement makes even less.

Lummox JR

I wanted to loop through all the vars that had a value of somesort. What would be a good way to do that?
In response to SSChicken
if(isnum(V))
var/A=input("What do you wish to set [V] to?","[V]",0) as num|null
V=A
In response to Goku72
Ok, I combined what you guys told me to do. It didnt work =(. So I wrote usr<<"1" "2" ect to see where it's not working. Here is the code

Lookatvars(mob/M in world)
usr<<"1"
for(var/V in M.vars)
usr<<"2"
if(isnum(V))
usr<<"3"
var/A=input("What do you wish to set [V] to?","[V]",0) as num|null
V=A

I get 1 "1" and about 34 "2" (There are 34 vars). I don't get any "3"

So what would be the problem. Also, Instead of giving each V a different value, I would like to choose which var I wanne change, then change it.
In response to SSChicken
Well, if you're looking for Administrator verbs...such as "Edit" there's great libraries and demos already out there ready to just be plugged in ^_^
for(var/V in src.vars)
if(src.vars[V]) //If it has a value
src << V //ouput it
In response to SSChicken
SSChicken wrote:
I wanted to loop through all the vars that had a value of somesort. What would be a good way to do that?

This way:
for(var/V in M.vars)
if(M.vars[V]) // if the value is not null or 0 or ""
...
However it's usually more useful to compare the value to the original.
for(var/V in M.vars)
if(M.vars[V] != initial(M.vars[V]))
...

Lummox JR
In response to Nadrew
While we're on the topic, does anyone know how to access a list of vars like that for world vars, or vars that aren't declared under an object?

<code>world status</code>

and

<code>var/game_speed</code>

For example?
In response to Foomer
Foomer wrote:
While we're on the topic, does anyone know how to access a list of vars like that for world vars, or vars that aren't declared under an object?

<code>world > status</code>

and

<code>var/game_speed</code>

For example?

To my knowledge, these variables aren't stored in any pre-defined list. You'd have to make your own procedure to save them to a list, and then read them from there.
var/list/WorldVars = list()
proc
SaveWorldVars()
WorldVars+="name"
WorldVars["name"]=world.name


Something like that, I'd guess.

~>Volte
In response to Foomer
Foomer wrote:
While we're on the topic, does anyone know how to access a list of vars like that for world vars, or vars that aren't declared under an object?

Nope. Some time back Deadron developed a very small debugging tool that had access to any datum's vars, but it wasn't able to handle world or global vars because of this one shortcoming in BYOND. Ideally I'd like to see a global vars list and a world.vars list to complement datums.

Lummox JR