Jump to content
xisto Community
Feelay

Making Something In Mysql Happen Only Once

Recommended Posts

Hey! I know I am asking alot. But much is happening theese days.
Sorry if I disturb with my questions.

The thing I am trying to do is:
Ex. If the user becomes level 2, he should get 5 skill points. I can't do this:

if($userlevel=5){mysql_query("UPDATE user SET skillpoints =$points+5");}
because then it would update everytime the code was loaded. I hope you understand what I am trying to do. If not, tell me ;) and i'll try to explain better.

Thanks //Feelay

Share this post


Link to post
Share on other sites

Hey Feelay,

All I noticed is the common mistake with doing comparisons.

if($userlevel = 5)
is not the same as
if($userlevel == 5)

The first one is an assignment which means you'll make $userlevel become 5 and will result in true.

The second one will not solve the issue though, you really need to do something that PerhapsYouSeen has suggested and add a column to record that they have gotten their points, then you just need to check that first before you give them points.

Cheers,

MC

Share this post


Link to post
Share on other sites

sorry ;) but I don't understand :P

He was explaining that your code does not test that the userlevel is 5.Your code is forcing userlevel to be level 5, which is probably not what you want.

Share this post


Link to post
Share on other sites

Oh. but my code was just an example.I just wanted to show, that if I wrote that code, it would give the user 5 skill points every time the page was loaded. but I want it to give the user 5 skill points, only the moment the user reach level 5 (for ex.).and between, I thougt of making a colum for the points, but the user will be able to "buy" health and strenght and stuff for theese points. so they (the points) will become 0 anyway =S

Edited by Feelay (see edit history)

Share this post


Link to post
Share on other sites

You have a script that increases a player's level if a condition is fulfilled, right? So why not just increase the points at the sime time you increase his/hers level?

Share this post


Link to post
Share on other sites

because the script says:If the user exp is more than 100, the user level should be changed to level 2 (etc.).. And that script runs everytime the user login. It would not work.

Share this post


Link to post
Share on other sites

OK, it seems that you definitively need a user status column in a table. With a value like "3065" if the user is at level 3 and has 65 lifehalth points. Or value 4100 if level 4 with 100 points. You change this value only once (when he goes to level 5) and you read the value each time the player logs in.

Share this post


Link to post
Share on other sites

because the script says:

 

If the user exp is more than 100, the user level should be changed to level 2 (etc.).. And that script runs everytime the user login. It would not work.


Why not "If the user exp is more than 100, the user level should be changed to level 2, and the user should get skill points (etc.).."?

Share this post


Link to post
Share on other sites

I don't know why my suggestion can not slove Feelay's problem ?

I make a column name 'last_received_points' which stores the last time he was received the bonus (supposing $last_received_points holds the last lever he was received bonus skillpoints)
then I combine with his lever, so it would exactly update just in once time

if ($user_level==5 and $last_received_points<5) {update skillpoints;}

if the user

"buy" health and strenght and stuff for theese points

I think it does not effect the last time he received bonus (or you can update it indepently if the user done sth above... if you want)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.