Author Topic: random short desc using switch statement  (Read 6761 times)

Offline petriomelony

  • Acquaintance
  • *
  • Posts: 34
    • View Profile
Re: random short desc using switch statement
« Reply #15 on: November 20, 2007, 03:03:10 PM »
hmm, i put something similar to:

Code: [Select]
string longdesc = NewLong();

outside of the create function, and then did

Code: [Select]
SetLong(longdesc);

inside the create, and it's still resetting the desc every time i quit and re-log.

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: random short desc using switch statement
« Reply #16 on: November 20, 2007, 03:21:53 PM »
The important part here is where you place the random() expression. That must be outside of the init and create. Otherwise it gets reset each time.

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: random short desc using switch statement
« Reply #17 on: November 20, 2007, 08:49:17 PM »
Try something like this...

after inherit, but before create():
Code: [Select]
string longdesc;
string NewLong();
string random_long();

in create():
Code: [Select]
SetLong( (: "random_long" :) );
AddSave("longdesc");
longdesc = NewLong();

below create():
Code: [Select]
string random_long() {
  if (!strlen(longdesc))
    longdesc = NewLong();
  return longdesc;
}
string NewLong() {
 ... previously discussed stuff ...
}

This will generate a new desc each time the object is created, but after that if it's being
loaded on a player it will restore the previous value of the desc.

Note this is completely untested, might need tweaking.


Offline petriomelony

  • Acquaintance
  • *
  • Posts: 34
    • View Profile
Re: random short desc using switch statement
« Reply #18 on: November 21, 2007, 09:41:04 AM »
hmm... after playing around with that code for a little, i can look at the wand once after cloning it, and then it gives errors after that... i believe it is a problem with AddSave.  here's the error:

Code: [Select]
*Left hand side of += is a number (or zero); right side is not a number.
Object: /domains/London/weap/wand#85 (/lib/std/item.c) at line 52

'<function>' at /secure/save/creators/p/petriomelony (<function>) at /:0
'cmdAll' at /secure/save/creators/p/petriomelony (/lib/command.c) at line 139
'do_look_obj' at /verbs/items/look at line 96
'do_look_at_obj' at /verbs/items/look at line 109
'eventShow' at /domains/London/weap/wand#85 (/lib/std/item.c) at line 262
'eventShow' at /domains/London/weap/wand#85 (/lib/events/look.c) at line 204
'GetExternalDesc' at /domains/London/weap/wand#85 (/lib/std/item.c) at line 52
Trace written to /log/runtime

Offline askrius

  • Acquaintance
  • *
  • Posts: 33
    • View Profile
    • Audit.Purge::under::construction
Re: random short desc using switch statement
« Reply #19 on: November 21, 2007, 11:17:48 AM »
make the variables global. ie. do not put them in the create nor init function. Then they will not get changed when you reload.

Here is a more complicated solution:  ;)

Since you are in essence creating discrete objects customized to user (i gather) then perhaps what you should do is "build" the object with your random calls? As such the end result would be a unique, call-able object. Same source file could be reused for players, updated when thier "unique" wand had to be replaced, etc....