Jump to content
  • 0

If/else work wrong


Vincent

Question


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

HI i at the moment i work at a script with a if else command. But the command dont work. Because the IF is

 

 

If (@tree_planted == 0)
 

checked by

query_sql "SELECT `tree_lvl` FROM `tree_db` WHERE `acc_id` = " + getcharid(3) + "", .@tree_planted;
 

This works. But after i update the  tree_lvl to "1" the new menu from else dont pop out but it have to because @tree_planted == 0 isnt 0 . 

 

 

 

Edited by King555
Link to comment
Share on other sites

13 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

The problem with your if statement is the missing dot. You are saving the selected value from the SQL query to .@tree_planted but then you use @tree_planted.

Furthermore, you should always use lower case commands (e.g. if instead of If and else instead of Else), unless the command requires any special case. It should work with upper case, but it is not very pretty.

Edited by DeadlySilence
  • Upvote 2
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Thanks :)



Whats wrong with my line?

 query_sql ("INSERT INTO `tree_db` (`last_water`) VALUES ('"+gettimetick(2)+"') WHERE `acc_id` = " + getcharid(3) + "");

Error message:

[SQL]: DB error - You have an error in your SQL syntax; check the manual that co
rresponds to your MySQL server version for the right syntax to use near 'WHERE `
acc_id` = 2000000' at line 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

I don't think you can use a WHERE condition in an INSERT query.

You either have to remove the condition like this:

query_sql("INSERT INTO `tree_db` (`last_water`) VALUES (" + gettimetick(2) + ")");

or, if you want to update an existing record, use UPDATE:

query_sql("UPDATE `tree_db` SET `last_water` = " + gettimetick(2) + " WHERE `acc_id` = " + getcharid(3));
Edited by DeadlySilence
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Ah good to know about the insert command.

 

I want to calculate the days betwen 2 dates. The dates are saved in DB via:

 

gettimestr("%Y%m%d",21)
 

 

Is there any command for this?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

Do you want to calculate it in an SQL query?

You can use something like

SELECT DATEDIFF(DATE('first date'), DATE('second date'));

to get the difference as an integer.


 

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

I played around with datadiff but cant get it to run correct.

 

my error:

[SQL]: DB error - Incorrect parameter count in the call to native function 'DATE
DIFF'
[Debug]: at c:\users\username\desktop\rathena_17383\src\map\script.c:14692 - SELE
CT DATEDIFF(day,'2007-06-05','2006-06-05')

My code:

 

query_sql "SELECT DATEDIFF(day,'2007-06-05','2006-06-05')", .@change_lvl;
 
Edited by Loco
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

The syntax is

DATEDIFF(first_date, second_date);

and it selects the difference between two dates. It doesn't take arguments regarding the type of difference (e.g. hour, day, month), it always returns the difference in days.

So the correct syntax for your query would be

query_sql "SELECT DATEDIFF('2007-06-05','2006-06-05')", .@change_lvl;

and would return 365.

Edited by DeadlySilence
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Thanks for your help, but this makes me crazy. 

Isn't possible to use variable's or what is the problem? maybe the %Y%m%d wothout - betwen Y M D?

 

 

20130628 is the .@tree_water;
query_sql "SELECT DATEDIFF('"+gettimestr("%Y%m%d",21)+"','.@tree_water')", .@tree_change_lvl;

mes .@tree_change_lvl;

Message from NPC = 0, but no error at the server.

Edited by Loco
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

Oh, now that's more complicated as the format you use isn't any standard I know...

I would suggest to use the format %Y-%m-%d rather than %Y%m%d for the .@tree_water variable.

If you decide to do this, you could easily use this query:

query_sql "SELECT DATEDIFF('" + gettimestr("%Y-%m-%d",21) + "','" + .@tree_water + "')", .@tree_change_lvl;
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

Thanks the script works now without any problems.

 

Now i try to make a instance map:

 

But i get this error:

 

[Info]: [Instance] Created: rent1 instanced.
[Error]: buildin_instance_attachmap: instance creation failed (rent1): -1
[Info]: [Instance] Destroyed rent1 instanced.

 

payon,150,155,1	script	NPC	723,{

set .@instance, instance_create("rent1 instanced", getcharid(1));
if( .@instance < 0 )
{
	mes "Failed to create the instance!";
	close;
}
if( instance_attachmap("rent1", .@instance) == "" )
{
 	instance_destroy(.@instance);
	mes "Failed to attach the map!";
	close;
}
instance_attach(.@instance);
instance_set_timeout(3600, 300, .@instance);
instance_init(.@instance);

warp "rent1", 20, 20;

}
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

It looks like you are still using the old instance system. You should update your working copy and have a look at the new system, it is easier than the old one.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  130
  • Topics Per Day:  0.03
  • Content Count:  528
  • Reputation:   18
  • Joined:  09/11/12
  • Last Seen:  

i try to instance the map with the script from http://rathena.org/wiki/Instancing. Is this the new or the old system at the wiki?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

That's the old one, but you can look at this file to find the new commands by searching "Instance Commands".

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...