ID:150263
 
How do I find whatever the code chooses as the random number?

Example..

obj
sword
equip()
usr.attack += rand(5,8)

unequip()
usr.attack -= (the random number)

Need to know this to unequip something, and subtract whatever random number it does.

Thanx for any help!

Make a var that equals rand(5,8) and add that to attack then you can unequip that number too example:


obj/Sword
var/Blah = rand(5,8)
icon='sword.dmi'
verb
Equip()
usr.attack+=Blah
Unequip()
usr.attack-=Blah


Hope that helps you some.
In response to Nadrew
Nadrew wrote:
Make a var that equals rand(5,8) and add that to attack then you can unequip that number too example:


> obj/Sword
> var/Blah = rand(5,8)
> icon='sword.dmi'
> verb
> Equip()
> usr.attack+=Blah
> Unequip()
> usr.attack-=Blah
>

Hope that helps you some.

I see what you mean, but I keep getting; expected a constant expression. Not sure what that means, forgot :(

obj
sword
name = "Short Sword"
var/dam = rand(5,8)
verb
get()
set src in oview(1)
Move(usr)
equip()
if(usr.hand == 0)
usr.attack+=dam
usr.range = 1
usr.hand = 1
usr << "You equip a [src]."
view() << "[usr] wields a [src]."
else
usr << "Either you already have something equipped or it's already equipped."
unequip()
if(usr.hand == 1)
usr.attack-=dam
usr.range -= 1
usr.hand = 0
view() << "[usr] puts [src] away."
else
usr << "You can't equip a [src]."

Thats what I have on this weapon.
Thanx again.
In response to Oblivian
Oblivian wrote:
Nadrew wrote:
Make a var that equals rand(5,8) and add that to attack then you can unequip that number too example:


> > obj/Sword
> > var/Blah = rand(5,8)
> > icon='sword.dmi'
> > verb
> > Equip()
> > usr.attack+=Blah
> > Unequip()
> > usr.attack-=Blah
> >

Hope that helps you some.

I see what you mean, but I keep getting; expected a constant expression. Not sure what that means, forgot :(



What line are you getting the error on?
In response to Nadrew
Nadrew wrote:
Oblivian wrote:
Nadrew wrote:
Make a var that equals rand(5,8) and add that to attack then you can unequip that number too example:


> > > obj/Sword
> > > var/Blah = rand(5,8)
> > > icon='sword.dmi'
> > > verb
> > > Equip()
> > > usr.attack+=Blah
> > > Unequip()
> > > usr.attack-=Blah
> > >

Hope that helps you some.

I see what you mean, but I keep getting; expected a constant expression. Not sure what that means, forgot :(



What line are you getting the error on?

var/Blah = rand(5,8)
In response to Oblivian
Ah you can't add obj vars to a mob, try making a mob var that does that.
In response to Nadrew
ok, got it thanx :)
In response to Oblivian
Oblivian wrote:
I see what you mean, but I keep getting; expected a constant expression. Not sure what that means, forgot :(

obj
sword
name = "Short Sword"
var/dam = rand(5,8)

rand() is not a constant expression. When you define the properties of the object sword, it is expecting contants for the values of the variables. This should be coded like this:
obj
sword
name = "Short Sword"
var/dam

New()
dam = rand(5,8)


This will assign each sword that is created in the game with its own random damage variable.
In response to Nadrew
Nadrew wrote:
Ah you can't add obj vars to a mob, try making a mob var that does that.

I'm not sure what you're talking about, Nadrew; this is an ordinary var, not a type /obj or /mob. From what I can tell, the only problem is that your altered version of the code mistakenly tries to assign rand(5,8) at compile-time instead of in the New() proc.

Lummox JR
In response to Lummox JR
Yes, I remembered I forgot about that but I believe it was stated before I had a chance to post mine.
(Neglecting to read the rest of this thread.)

run a proc that you want a random value used for, and do it like so:

proc/Random()
var/random = rand(1,10)
usr.status = random
usr << "[random] is the value."

You can only declare variables with random values if they are in an active procedure, like a verb or a proc. Don't try declaring them as an object variable, because the compiler won't like it.