ID:797624
 
(See the best response by LordAndrew.)
Code:
mob
npc
var
disp = 45
attack = 90
flee = 40
greet = ""
detectplayer = 0
proc
var
roll = 0
GreetRoll(mob/npc/M)
switch
if(M.disp <= 25 && M.detectplayer == 1)
roll = rand(1,3)
switch
if(roll == 1)
M.greet = "What are you doing around here? Get lost!"
if(roll == 2)
M.greet = "You know I hate you, and you know I can't tand your presence. Go away."

if(roll == 3)
M.greet = "I hate you so much..."


Problem description:

I was working on the AI for a game I'm working on. I haven't used DM in MONTHS, so I have pretty much forgotten everything. The compiling results are:


if(M.disp <= 25 && M.detectplayer == 1) - missing expression

if(roll == 1) - missing expression




Best response
switch()

switch(roll)
if(1) // things
if(2) // other things
// etc
Dammit, can't believe I forgot that the switch forgot (), thanks LordAndrew. :) Also, since I'm detecting the disp and detectplayer vars, should I use those in the switch at the top?
EDIT: Nevermind , turns out the switch statement was useless, and caused lots of errors, this worked:

mob
npc
var
disp = 45
attack = 90
flee = 40
greet = ""
detectplayer = 0
proc
GreetRoll(mob/npc/M)
var
roll = 0
if(M.disp >= 0 && M.disp <= 30)
roll = rand(1,3)
if(roll == 1)
M.greet = "What are you doing around here? Get lost!"
if(roll == 2)
M.greet = "You know I hate you, and you know I can't tand your presence. Go away."
if(roll == 3)
M.greet = "I hate you so much..."
else if(M.disp >= 31 && M.disp <= 44)
roll = rand(1,3)
if(roll == 1)
M.greet = "Oh, it's *you*..."
if(roll == 2)
M.greet = "Don't bother me, and their won't be trouble."
if(roll == 3)
M.greet = "You're standing on very thin ice with me, don't make me angry."
else if(M.disp >= 45 && M.disp <= 60)
roll = rand(1,3)
if(roll == 1)
M.greet = "Greetings."
if(roll == 2)
M.greet = "How do you do?"
if(roll == 3)
M.greet = "Hi."
else if(M.disp >= 61 && M.disp <= 69)
roll = rand(1,3)
if(roll == 1)
M.greet = "Greetings, friend."
if(roll == 2)
M.greet = "Hello, traveler."
if(roll == 3)
M.greet = "Are you looking for talk?"
else if(M.disp >= 70 && M.disp <= 89)
roll = rand(1,3)
if(roll == 1)
M.greet = "Good to see you."
if(roll == 2)
M.greet = "I'm happy o see a trusted face here."
if(roll == 3)
M.greet = "Hey, friend."
else if(M.disp >= 90 && M.disp <= 100)
roll = rand(1,3)
if(roll == 1)
M.greet = "My favorite friend, glad to see you right now!."
if(roll == 2)
M.greet = "You're someone I actually like.I'd be glad to talk."
if(roll == 3)
M.greet = "It would be great to talk."
In response to BeignetLover
Instead of your roll, you can simply pick() a random item from a list of messages. Also, you can still use switch() to see if a variable is within a set of bounds.

switch(M.disp)
if(0 to 10) m.greet = pick("I hate you.", "You suck.", "Go away.")
pick never works when I use it, if I do, it never uses a RANDOM value, just the same one over & over.
In response to BeignetLover
BeignetLover wrote:
pick never works when I use it, if I do, it never uses a RANDOM value, just the same one over & over.

From the DM Reference


Also, to pick a value randomly from a list, simply pass the list as the sole argument into pick(). In this case, there is no provision for weighting the probabilities. All items in the list are equally likely.