Welcome Guest ( Log In | Register )




                Web Hosting

2 Pages V   1 2 >  
Reply to this topicNew Topic
Making Something In Mysql Happen Only Once
Feelay
post Feb 18 2008, 09:23 PM
Post #1


Kinda N00B
Group Icon

Group: Members
Posts: 235
Joined: 13-January 08
From: Sweden
Member No.: 27,579


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:
CODE
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 smile.gif and i'll try to explain better.

Thanks //Feelay
Go to the top of the page
 
+Quote Post
PerHapsYouSeen
post Feb 19 2008, 04:41 AM
Post #2


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 23
Joined: 24-October 07
Member No.: 25,689


why dont't you add a column to store the last time he was got skill points. Isn't is much easier.

This post has been edited by PerHapsYouSeen: Feb 19 2008, 04:45 AM
Go to the top of the page
 
+Quote Post
mastercomputers
post Feb 19 2008, 08:23 AM
Post #3


PESTICIDAL MANIAC
Group Icon

Group: Members
Posts: 630
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27


Hey Feelay,

All I noticed is the common mistake with doing comparisons.

CODE
if($userlevel = 5)

is not the same as
CODE
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

Go to the top of the page
 
+Quote Post
Feelay
post Feb 19 2008, 11:09 AM
Post #4


Kinda N00B
Group Icon

Group: Members
Posts: 235
Joined: 13-January 08
From: Sweden
Member No.: 27,579


sorry tongue.gif but I don't understand tongue.gif
Go to the top of the page
 
+Quote Post
yordan
post Feb 19 2008, 01:29 PM
Post #5


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,296
Joined: 16-August 05
Member No.: 7,896
myCENTs:1.64


QUOTE(Feelay @ Feb 19 2008, 12:09 PM) [snapback]119168[/snapback]
sorry tongue.gif but I don't understand tongue.gif

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.
Go to the top of the page
 
+Quote Post
Feelay
post Feb 19 2008, 04:15 PM
Post #6


Kinda N00B
Group Icon

Group: Members
Posts: 235
Joined: 13-January 08
From: Sweden
Member No.: 27,579


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

This post has been edited by Feelay: Feb 19 2008, 04:18 PM
Go to the top of the page
 
+Quote Post
pyost
post Feb 19 2008, 06:02 PM
Post #7


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,053
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500
myCENTs:36.94


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?
Go to the top of the page
 
+Quote Post
Feelay
post Feb 19 2008, 08:10 PM
Post #8


Kinda N00B
Group Icon

Group: Members
Posts: 235
Joined: 13-January 08
From: Sweden
Member No.: 27,579


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.
Go to the top of the page
 
+Quote Post
yordan
post Feb 19 2008, 10:01 PM
Post #9


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,296
Joined: 16-August 05
Member No.: 7,896
myCENTs:1.64


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.
Go to the top of the page
 
+Quote Post
pyost
post Feb 19 2008, 10:59 PM
Post #10


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,053
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500
myCENTs:36.94


QUOTE(Feelay @ Feb 19 2008, 09:10 PM) [snapback]119186[/snapback]
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.).."?
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: