Vincent Posted June 27, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Share Posted June 27, 2013 (edited) 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 June 27, 2013 by King555 Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted June 27, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted June 27, 2013 (edited) 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 June 27, 2013 by DeadlySilence 2 Quote Link to comment Share on other sites More sharing options...
Vincent Posted June 27, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted June 27, 2013 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 Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted June 27, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted June 27, 2013 (edited) 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 June 27, 2013 by DeadlySilence 1 Quote Link to comment Share on other sites More sharing options...
Vincent Posted June 28, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted June 28, 2013 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? Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted June 28, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted June 28, 2013 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. Quote Link to comment Share on other sites More sharing options...
Vincent Posted June 29, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted June 29, 2013 (edited) 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 June 29, 2013 by Loco Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted June 29, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted June 29, 2013 (edited) 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 June 29, 2013 by DeadlySilence Quote Link to comment Share on other sites More sharing options...
Vincent Posted June 29, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted June 29, 2013 (edited) 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 June 29, 2013 by Loco Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted June 29, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted June 29, 2013 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; 1 Quote Link to comment Share on other sites More sharing options...
Vincent Posted June 29, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted June 29, 2013 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; } Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted June 30, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted June 30, 2013 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. Quote Link to comment Share on other sites More sharing options...
Vincent Posted June 30, 2013 Group: Members Topic Count: 130 Topics Per Day: 0.03 Content Count: 528 Reputation: 18 Joined: 09/11/12 Last Seen: March 5, 2020 Author Share Posted June 30, 2013 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? Quote Link to comment Share on other sites More sharing options...
DeadlySilence Posted June 30, 2013 Group: Members Topic Count: 7 Topics Per Day: 0.00 Content Count: 181 Reputation: 53 Joined: 04/07/13 Last Seen: August 23, 2014 Share Posted June 30, 2013 That's the old one, but you can look at this file to find the new commands by searching "Instance Commands". Quote Link to comment Share on other sites More sharing options...
Question
Vincent
HI i at the moment i work at a script with a if else command. But the command dont work. Because the IF is
checked by
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 .
Link to comment
Share on other sites
13 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.