ID:138965
 
Code:
client/Topic(href,href_list[])
switch(href_list["action"])
if("back")
switch(href_list["page"])
if("")
//usr<<"[href_list["page"]]"
return ..()
else
usr<<browse("[href_list["page"]]","window= ")
if("stage")
usr<<"[href_list["page"]]"
usr<<browse("[stages][((href_list["page"]!="")?"<a href='?action=back;page=href_list["page"]'>Back</a>":"")]","window= ")
else
return ..()


Problem description:
So what I'm trying to do but having problems accomplishing is accessing or referencing my global variable after it's passed as text. I'm not sure how much sense that made so I'll reiterate. I've got a text string that I'm trying to use to target my global variable which has the same name as my text string. How do I address that global variable from my string?

href_list["page"] is a text output I'd like to access my global/var with it.
You can't access it because text cannot be converted directly into a variable unless using the vars var.

I'd suggest using a list
In response to Ill Im
So lists can be converted? I did try using vars var but couldn't figure out how to directly target global vars from it.
In response to Zaladus
 var/list/varList = list("Variable")
...
var/string = "Variable"
world<<varList[string]
As Ill Im said, you can use a list.

var
global_var = 5


If href_list["page"] is the string "global_var", there's no easy way to be able to reference the global variable. But with lists, you can do this:

var
list/globals = list("global_var" = 5)

// then you can reference the global variable as:
globals["global_var"]

// or, when href_list["page"] = "global_var"
globals[href_list["page"]]
In response to Forum_account
I really wish I would've clicked back to this page, and read your post before I remade it.

//Description Pages
var/global/list/pages = list("stage",{"<h3><center><b><u>-=Stages=-</b></u></h3></center><br><b><p><h4>Critical:</h4><br>Stage 1 <-> 6.25%<br>Stage 2 <-> 12.5%<br>Stage 3 <-> 25%<br>Stage 4 <-> 33.3%<br>Stage 5 <-> 50%</p><p>Type:<br><DFN>STAT.</DFN></p> <p>Delay:<br><DFN>4s.</DFN></p><p>Duration:<br><DFN>1m.</DFN></p>"},"calmmind",{"<h3><center><b><u>-=Calm Mind=-</b></u></h3></center><br><b><p>Effect:<br><DFN>Raises the user's Special Attack and Special Defense by 1 <a href='?action=stage;page=calmmind'>stage</a> each.</DFN></p> <p>Type:<br><DFN>STAT.</DFN></p> <p>Delay:<br><DFN>4s.</DFN></p> <p>Duration:<br><DFN>1m.</DFN></p>"})

...

client/Topic(href,href_list[])
switch(href_list["action"])
if("back")
switch(href_list["page"])
if("")
return ..()
else
for(var/tmp/s=1;s<=pages.len;s++)
if("[href_list["page"]]"=="[pages[s]]")
usr<<browse("[pages[(s+1)]]","window= ")
if("stage")
for(var/tmp/s=1;s<=pages.len;s++)
if("[href_list["action"]]"=="[pages[s]]")
usr<<browse("[pages[(s+1)]][((href_list["page"]!="")?"<a href='?action=back;page=[href_list["page"]]'>Back</a>":"")]","window= ")
else
return ..()


I wouldn't need the FOR loops T_T.
In response to Zaladus
Thank you both it looks so much better and works like a charm.

client/Topic(href,href_list[])
switch(href_list["action"])
if("back")
switch(href_list["page"])
if("")
return ..()
else
usr<<browse("[pages[href_list["page"]]]","window= ")
if("stage")
usr<<browse("[pages[href_list["action"]]][((href_list["page"]!="")?"<a href='?action=back;page=[href_list["page"]]'>Back</a>":"")]","window= ")
else
return ..()