Author Topic: [AXE] call a "random" subroutine  (Read 3168 times)

0 Members and 1 Guest are viewing this topic.

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
[AXE] call a "random" subroutine
« on: December 07, 2012, 09:42:50 am »
Hi guys

How would i be able to call a random subroutine?

I mean, if i have for example 5 subroutines...
EVENT1
EVENT2
EVENT3
EVENT4
EVENT5

how could i call one of those subroutines randomly?

for example when user does something, it should call a subroutine, but it has to be randomly chosen from that 5 (or maybe more...)
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: [AXE] call a "random" subroutine
« Reply #1 on: December 07, 2012, 09:57:43 am »
1.0.0 introduced a set of nice functions that can do this quite easily. The idea is to make a set of data containing the addresses of those routines, and then choose randomly from that set.

.Make set of data containing addresses of routines using the L list token
Data(LEVENT1r,LEVENT2r,LEVENT3r...LEVENTNr)->GDB1
.Choose randomly and execute that routine using the (LABELADDRESS)() syntax
({rand^n*2+GDB1}r)()

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: [AXE] call a "random" subroutine
« Reply #2 on: December 07, 2012, 10:35:58 am »
oooh cool squidgetx :D

And doesn't the rand create something greater then 5 sometimes? :/
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: [AXE] call a "random" subroutine
« Reply #3 on: December 07, 2012, 10:37:19 am »
oooh cool squidgetx :D

And doesn't the rand create something greater then 5 sometimes? :/
Yes, this is the aim of the "^n" after the "rand". "rand^n" returns a random number between 0 and n-1
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: [AXE] call a "random" subroutine
« Reply #4 on: December 07, 2012, 10:40:38 am »
oooh ok xD me so stupid :p
thx
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER