random.n

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 9 months ago #5194 by Krell
random.n was created by Krell
It's been a while since I've done any building and I see that tbaMUD has bumped to a new version since so I don't know if this question is still relevant. Anyhow, I've noticed that in scripts where I try to call on random.n twice with two different values of n both calls are set to the same value. Is this a design flaw of the script or merely a limitation?

*
* Commute Path - Gillian
*       by Krell
*     12 June 2013
*    tbaMUD Z163
*
set H_VNUM 16328
set LOBBY 16301
*
* I've made L_TIME a function of S_TIME as two random.# statements
* seem to always choose the same value which suggests that two or
* more random.# statements in a script are not independent.  I am 
* probably wrong about this.
*
* Modify at your own discretion.
*
set S_TIME %random.3%
set L_TIME %S_TIME% + 1
*set OPEN_TIME 8:00
*set CLOSE_TIME 18:00
context %self.id%

wait until 8:00
set in_commute_z163 1
global in_commute_z163
stand
%teleport% %self% %LOBBY%
%echo% %self.name% enters the lobby doors and walks toward the library.
wait %L_TIME% s
south
wait %S_TIME% s
%echo% %self.name% walks toward the Service Desk.
wait %L_TIME% s
sit
wait %S_TIME% s
%echo% %self.name% opens up some ledgers and turns on %self.hisher% computer.
set in_commute_z163 0
global in_commute_z163
wait until 18:00
set in_commute_z163 1
global in_commute_z163
%echo% %self.name% looks through a ledger, signs off %self.hisher% name.
wait %L_TIME% s
%echo% %self.name% puts some ledgers away.
wait %S_TIME% s
%echo% %self.name% turns off %self.hisher% computer.
wait %S_TIME% s
stand
wait %S_TIME% s
%echo% %self.name% stretches %self.hisher% back.
wait %L_TIME% s
%echo% %self.name% walks toward the library entrance doors
wait %S_TIME% s
north
wait %L_TIME% s
%echo% %self.name% crosses the lobby and leaves the building.
global in_commute_z163
%echo% %self.name% looks through a ledger, signs off %self.hisher% name.
wait %L_TIME% s
%echo% %self.name% puts some ledgers away.
wait %S_TIME% s
%echo% %self.name% turns off %self.hisher% computer.
wait %S_TIME% s
stand
wait %S_TIME% s
%echo% %self.name% stretches %self.hisher% back.
wait %L_TIME% s
%echo% %self.name% walks toward the library entrance doors
wait %S_TIME% s
north
wait %L_TIME% s
%echo% %self.name% crosses the lobby and leaves the building.
%teleport% %self% %H_VNUM%
*
* Variable Checking.  Make sure global is where it's supposed to be.
* Perhaps superfluous when using wait-until?
*
if %time.hour% > 8 && %time.hour% < 18 && %in_commute_z163%
   set in_commute_z163 0
   global in_commute_z163
elseif %time.hour% >= 18 || %time.hour% > 0 && %time.hour% <= 8 && !%in_commute_z163%
   set in_commute_z163 1
   global in_commute_z163
end

PS. I may have asked this before, but it may have been on the MUD, I see no logs of the event and I don't see it recorded anywhere here in the forum. So, for posterity...

Please Log in or Create an account to join the conversation.

More
6 years 3 months ago #5377 by Parnassus
Replied by Parnassus on topic random.n
Sorry, I don't know how I missed this. Without doing any trials at all, I have to ask:
Is this the dreaded set vs eval thing?

Sorry if this is a silly question. I've found myself a bit confused lately and its one of those things that's been explained and explained to me and I never quite got it right.

Please Log in or Create an account to join the conversation.

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago #5384 by Krell
Replied by Krell on topic random.n
No, I don't think so. At least using eval shouldn't make a difference as far as randomizing the values goes and might have a higher penalty to execute compared to set. I don't remember if I attempted it with eval or not though, at the time I didn't see the advantage.

Please Log in or Create an account to join the conversation.

More
6 years 3 months ago #5391 by Parnassus
Replied by Parnassus on topic random.n
This is my set vs eval test:
set S_TIME %random.3%
set L_TIME %S_TIME% + 1
%echo% Set %S_TIME%
%echo% Set %L_TIME%
eval S_TIME %random.3%
eval L_TIME %S_TIME% + 1
%echo% Eval %S_TIME%
%echo% Eval %L_TIME%
set S_TIME %random.3%
eval L_TIME %S_TIME% + 1
%echo% Set %S_TIME%
%echo% Eval %L_TIME%

And this is my output:
Set 3
Set 3 + 1
Eval 2
Eval 3
Set 1
Eval 2

This indicates to me (not totally sure) that set or eval works for your S_TIME (although set would be better) but your L_TIME has to be eval.

Please Log in or Create an account to join the conversation.

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago #5392 by Krell
Replied by Krell on topic random.n
Perhaps, but this was over half a year ago and I don't remember if I used eval or not. With my local version of tba currently not functional and my internet connection being what it is at the moment I can't even make changes or test anything. :-(

Please Log in or Create an account to join the conversation.

More
6 years 3 months ago #5394 by Parnassus
Replied by Parnassus on topic random.n
Yeah, its funny for me to be thinking about this six months later :) But its good training for me to try anyway.

Please Log in or Create an account to join the conversation.

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago - 6 years 3 months ago #5395 by Krell
Replied by Krell on topic random.n
I just can't imagine me not having at least tried eval or eval working any differently than it is now. Perhaps I had a reason that made sense to me at the time but now I can't recall.

Addendum

I was just going over your findings. I think you get the same results whether you use set or eval and L_TIME still has to be a function of S_TIME. Maybe I did try eval after all and found no discernable advantage?

Anyhow, my trigger works as is, it would work well with how you're suggesting and I highly appreciate you looking into it. Thank you.
Last edit: 6 years 3 months ago by Krell.

Please Log in or Create an account to join the conversation.

Time to create page: 0.114 seconds