ID:820774
 
(See the best response by Stephen001.)
Hello!
Code:
words
TestA
TestB
TestC
mob
verb
PickWord()

var/g = pick(typesof(/words))
usr << g


Problem description:
I am trying to make it so a certain verb/proc picks at random a path. In the code above, I want it to pick from either TestA, TestB or TestC and display it to the user(the list I am going to create is going to be extremely huge).
Is it not working as you expected? Or are you asking if that is a good method to do so?

The only issue I can see is that you're not removing the base path (/words) from the list: pick(typesof(/words) - /words)
words
TestA
TestB
TestC
mob
verb
PickWord()

var/g = pick(typesof(/words)-/words) //typesof() would include all paths, including /words, as DarkCampainger said. Therefore, remove /words from the returned list with a simple - operator.
usr << path2text(g) //This is just for output. You can't send the user a path just like that. Use text instead.
Alright, I figured the problem. It was because I did not set the output window as a default window, as a result the path was not being outputted correctly.
Yet, I got another little problem.
mob
verb
PickWord()
var/g = pick(typesof(/words) - /words)
var/words/A = g
world << A.name
words
var/name
var/possibility=list()
Test
name = "Test"
possibility=list("T", "E", "S", "T")
TestA
name = "TestA"
possibility=list("T", "E", "S", "T", "A")
TestB
name = "TestB"
possibility=list("T", "E", "S", "T", "B")

What I need up there is to output the name instead of the path itself. It gives me a runtime error when I use the verb.
That is:
{
runtime error: Cannot read /words/TestB (/words/TestB).name
proc name: PickWord (/mob/verb/PickWord)
usr: Alitron123 (/mob)
src: Alitron123 (/mob)
call stack:
Alitron123 (/mob): PickWord()
}
Best response
mob
verb
PickWord()
var/g = pick(typesof(/words) - /words)
var/words/A = g
world << A.name


g is a type, a template, you need to actually make an object from it:

mob
verb
PickWord()
var/g = pick(typesof(/words) - /words)
var/words/A = new g()
world << A.name
In response to Stephen001
Stephen001 wrote:
g is a type, a template, you need to actually make an object from it:
Exactly what I was trying to do, thank you!

----

I got another problem:
mob
verb
Information()
set name = ".info"
var/g = list(typesof(/words/) - /words)
var/n = length(g)
usr << "<font color = purple>There are [n] paths in the database."
words
var/name
// var/possibility=list()
One
name = "Dog"
// possibility=list("T", "E", "S", "T")
Two
name = "Cat"
// possibility=list("T", "E", "S", "T", "A")
Three
name = "Banana"
// possibility=list("T", "E", "S", "T", "B")

I am trying to get the game to calculate the number of possible paths under \words, it outputs only 1 though.


In response to Alitron123
typesof() returns a list of the available types.

This line:
var/g = list(typesof(/words/) - /words)

is creating a list of a list. So the first element of g would be a list itself. So there is only one element in g.
Ah, I got that.
I just didn't need the list() part. Thanks.