Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Help with lottery coding DBP

Author
Message
Ozone88101
11
Years of Service
User Offline
Joined: 27th Nov 2012
Location:
Posted: 14th Sep 2013 21:03
trying to write a simple program our GW2 guild can use for a lottery and not sure why it isnt working and how to make it function easier/better. I would appreciate any help.

What I am trying to get it to do:

accept the prize amount
accept number of entries
enter in names for each entry
(ie. joe buys 5 tickets so I enter his name 5 times.)
randomly draw a name from the entries
and split the pot amount by 50% and 25%

here is what I have so far:


any help please? thanks!

There are 10 types of people in this world; Those that know Binary and those that don't.
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 15th Sep 2013 14:00 Edited at: 15th Sep 2013 14:01
Quote: "trying to write a simple program our GW2 guild"

I salute your choice of MMO. I play an Asura Mesmer and a Charr Thief.

The problem with your code is to do with variable scope. The scope of a variable is its "lifetime", or more simply is the lines of code in which it exists. Variables declared in functions exist only within those functions. Equally functions do not have access to variables declared outside themselves unless:
1. They are parsed to the function as parameters
2. They are explicitly declared as global
3. They are arrays and are not explicitly declared as local (arrays default to global)

So in your code, the Drawing() function tries to use the prize variable but prize is not a global. Therefore the line

is actually creating a new variable called prize that is local to Drawing(), initializing it to 0 and then dividing it by 2 which of course gives 0.

To get your code working, I just modified it so that you parse all the necessary variables as parameters to the functions.


I can't say I really understand the logic here though lol. What happens to the 25% that doesn't go to the winner or back into the pot?

Also for future reference, watch your indentation. I've corrected it in the example above. The rule of thumb is that you should indent code within structure blocks that have a beginning and an end (e.g. if..endif, function..endfunction, for..next etc.).

Hope that helps.

Ozone88101
11
Years of Service
User Offline
Joined: 27th Nov 2012
Location:
Posted: 16th Sep 2013 06:26
Thanks a lot, that has worked excellent. I had to change the "prize" to prize# so that it would give decimals.

I indented in a way that looks good for me so i can find things easier. I have also been know to go crazy on my REM lines too lol

But again, thanks! works perfectly!

And to answer your question: 50% to winner, 25% to next pot, 25% to guild bank for various things.

Also, on Sea of Sorrows server, I got 80 Human Thief (Commander), Human Mesmer, Human Necromancer, Norn Gurdian, Human Elementalist. Currently working on Asura Warrior, Sylvari Ranger and Charr Engineer. Over 4000 hours on two accounts and still no legendary lol.

There are 10 types of people in this world; Those that know Binary and those that don't.

Login to post a reply

Server time is: 2024-02-24 23:50:58
Your offset time is: 2024-02-24 23:50:58