Display Hyperlinks from a text file

Posted by Fletchling on Sun 15 Oct 2006 01:02 PM — 3 posts, 14,979 views.

Australia #0
I want to incorporate the ability to display Hyperlinked text derived from content in a text file. For the purpose of this post, I've stripped out everything that isn't directly part of
1. open file
2. get line of text from file
3. display line
4. repeat until eof

Current alias

<aliases>
<alias
match="showlink"
enabled="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>for line in io.lines ("link.txt") do
Hyperlink ("line")
end -- for
</send>
</alias>
</aliases>


If I replace the "Hyperlink" function with "Note" it finds the text just fine, but as it is I can only get the following error;

[string "Alias: "]:2: attempt to call global 'Hyplerlink' (a nil value)
stack traceback:
[string "Alias: "]:2: in main chunk

The first two lines of text in example link.txt file are;
("run 2s3en ","Bakery: run 2s3en Food for the hungry adventurer. ","black","red",0)
("run 2s5en ","Provisions: run 2s5en General supplies (torches, containers, etc.). ","black","red",0)

These two lines work just fine when embedded as part of an Alias that directly uses the Hyperlink function. The purpose of this is part of my happy plan to add yet more options for navigating and infomation onscreen, particularly with my maps.

Advice gratefully appreciated.
Australia Forum Administrator #1
You have three problems here:

  • There error says: attempt to call global 'Hyplerlink' (a nil value)

    You have misspelt "Hyperlink" - although it looks OK in the alias you posted.
  • You have quoted "line" here:


    Hyperlink ("line")


    That will merely hyperlink the word "line" not the line variable. I presume you mean:


    Hyperlink (line)

  • Even if you fixed that, the data from the file is just a string, so it would then be doing this:


    Hyperlink ('("run 2s3en ","Bakery: run 2s3en Food for the hungry adventurer. ","black","red",0)')


    If you got rid of the brackets from the start and end of each line, this would work:


    -- example line
    line = '"run 2s3en ","Bakery: run 2s3en Food for the hungry adventurer. ","black","red",0'

    -- split at commas, feed back in as a set of arguments
    Hyperlink (unpack (utils.split (line, ",")))
Australia #2
Nick,

Thank you, the typo was inserted at post time, I did have it right in the alias. Adding the utils.split and removing the ()s as you suggested worked as well as I could hope for.

Adding hyperlinks for certain actions to my triggers, aliases and zone-note files really does me more information at every step. Is there nothing Mushclient can't do?

Thanks again.