ID:143927
 
After taking a break from DM for awhile i've decided to come back to do something, thats been haunting me for awhile.

I was working on building a little stargate system to learn many diffrent parts of DM at once using lists and vars. My problem is that i get a runtime error after i complete dialing the address to test if it worked i was making sure that an invisable part of the stargate was made solid.

Am i on the right track to doing this?
obj
Stargate
peices
left
icon='PGate.dmi'
icon_state="Gleft"
middle
icon='PGate.dmi'
icon_state="Gmiddle"
right
icon='Pgate.dmi'
icon_state="Gright"
chevrons
C1
icon='PChevron.dmi'
icon_state="C1"
C2
icon='PChevron.dmi'
icon_state="C2"
C3
icon='PChevron.dmi'
icon_state="C3"
C4
icon='PChevron.dmi'
icon_state="C4"
C5
icon='PChevron.dmi'
icon_state="C5"
C6
icon='PChevron.dmi'
icon_state="C6"
C7
icon='PChevron.dmi'
icon_state="C7"

Gate//This becomes solid
var/address=""
DHD
icon='PDHD.dmi'
icon_state="DHD"
var/memory=""
var/obj/Stargate/Gate/A
DblClick()
var/current
memory=""
current=""
current = input ("Dial me") as num|null
current = input ("Dial me") as num|null
current = input ("Dial me") as num|null
current = input ("Dial me") as num|null
current = input ("Dial me") as num|null
current = input ("Dial me") as num|null
memory += num2text(current)
if((current==A.address in world))
A.density=1



Although you didn't post your error, I would guess it's this:
>           if((current==A.address in world))
> A.density=1
>


What you need to do is LOOP through all the /obj/Stargate/Gate/ in the world, but you're going about it the wrong way.

Use a for loop:
http://developer.byond.com/docs/ref/info.html#/proc/for/list

Sorry I can't explain more, off to beat someone in their own game.
In response to DarkCampainger
But won't that make all stargates in the network solid..... how would i aim it then between the source and destination?
In response to Yorae
Well, it all depends on how you want to handle it.

You can use the for() loop like so:
for(A in world) //Since A is a defined variable, it will search for the type that A was type-casted as.
if(A.address==current) //If the address of the gate we found is the same as the one we're dialing...
A.density=1


However, that's not a very short way to do it, and it would take even more code to determine if a gate was actually found. Not to mention you would have to do it yet again when the player stepped through.

You can also create a list of valid addresses and their respective gates using an associative list:
var/list/gate_addresses = list()
obj/Stargate/Gate/New()
if(address)
gate_addresses[address]=src //Add the Gate's address to the list, and set the associated value to the gate object itself.
..()


Now we can check if an address is valid with a simple in statement:
if(current in gate_addresses)


And access the gate connected to that address with this:
var/obj/Stargate/Gate/A = gate_addresses[current]


You should be able to put it all together, but if you want some clarification, I'll be here for a bit.
In response to DarkCampainger
Before anything i would like to say thanks for the help, but i'm still having problems i can't seem to aim it. Making the gate infront of my solid and the one which i'm dialing in the gate network solid, without effecting the rest of the network.

I've tried using your "for" one but it doesn't even make them solid anymore i diden't understand your list one.

Could you explain it abit more indeapth and how i could implement it.
In response to Yorae
First, are you sure you set the addresses for all the gates?

If so, can you show me what you've got so far? I can't think of why the for() loop wouldn't be working if the addresses are all set up.

Also, something else I noticed, you're constantly resetting the current variable when I think you want to be adding to it.
In response to DarkCampainger
This is all i did i check the gates address and there all set. If you mean at the current in the beginning i do that so that the next time you dial it clears the DHD or did you mean something else?
    DHD
icon='PDHD.dmi'
icon_state="DHD"
var/memory=""
var/obj/Stargate/Gate/A
DblClick()
var/current
memory=""
current=""
current = input ("Dial me") as num|null
current = input ("Dial me") as num|null
current = input ("Dial me") as num|null
current = input ("Dial me") as num|null
current = input ("Dial me") as num|null
current = input ("Dial me") as num|null
memory += num2text(current)
for(A in world)
if(A.address==current)
A.density=1
In response to Yorae
I mean these:
>
> current = input ("Dial me") as num|null
> current = input ("Dial me") as num|null
> current = input ("Dial me") as num|null
> current = input ("Dial me") as num|null
> current = input ("Dial me") as num|null
> current = input ("Dial me") as num|null


Each time you're reseting it to a new value, I think you want to add it.
In response to DarkCampainger
But i thought that if i added too it with += wouldn't that just add to the address such as 1+2+3+4+5+6=21 will the same as 6+5+4+3+2+1 how would i do this then?
In response to DarkCampainger
Something like this:
> >
> > current = "[input("Dial me") as num|null]"
> > current += "[input("Dial me") as num|null]"
> > current += "[input("Dial me") as num|null]"
> > current += "[input("Dial me") as num|null]"
> > current += "[input("Dial me") as num|null]"
> > current += "[input("Dial me") as num|null]"
>


The using brackets in a string embeds an expression, so that changes them all to text.
In response to DarkCampainger
It all works thanks for the help.