1 decade ago by ShawnSwander
This isn't within impact Its on my server so I can't just declare it under ig.game but I need to pass from_sql out of the function its in and my attempt at return didn't work perhaps someone could point out what I need to change to do this?
If you scroll down to the comment
that is where I can't pass the variable.
If you scroll down to the comment
//lost it
that is where I can't pass the variable.
socket.on('moveitem', function (player_id,itemlist_id,item_id,move_from,move_to,posx,posy,land){ connection.escape(player_id,itemlist_id,item_id,move_from,move_to,posx,posy,land) console.log(player_id,itemlist_id,item_id,move_from,move_to) var to_sql = null; var from_sql = null; var to_data = null; var from_data = null; sql ="SELECT next_turn,action_time,posx,posy,land FROM game_moblist WHERE id = "+player_id; connection.query(sql, function(err, rows, fields) {if (err) throw err if ((rows[0])&&rows[0].next_turn < new Date().getTime()){ if (move_from!=move_to&&move_to!=null){ sql="UPDATE game_moblist SET `next_turn`="+(new Date().getTime()+rows[0].action_time); connection.query(sql, function(err, rows, fields) {if (err) throw err;}); switch(move_from){ case 0://ground //check if its last item in hex here from_sql = "DELETE FROM `game_itemlist` WHERE `id` ="+itemlist_id; break; case 1://sack sql = "SELECT sack FROM `game_moblist` WHERE id="+player_id; connection.query(sql, function(error, rows, fields){ var sack = rows[0].sack.split(",") for (i=0;i<sack.length;i++){ if (sack[i]==item_id.toString()){ sack[i]="0"; sack = sack.join(); from_sql="UPDATE game_moblist SET sack='"+sack+"' WHERE id="+player_id i=sack.length } } }); //lost it console.log(from_sql) break; } switch(move_to){ case 0: to_sql="INSERT INTO game_itemlist (id,posx,posy,land) VALUES "+item_id+","+posx+","+posy+",'"+land+"'"; break; case 1://sack sql ="SELECT sack FROM `game_moblist` WHERE id="+player_id; connection.query(sql, function(error, rows, fields){ var sack = rows[0].sack.split(",") for (i=0;i<sack.length;i++){ if (sack[i]=="0"){ if(typeof item_id === "number"){ sack[i]= item_id.toString() sack = sack.join(); to_sql ="UPDATE game_moblist SET sack='"+sack+"' WHERE id="+player_id i=sack.length to_data = sack; } } } }); break; } console.log(from_sql,to_sql) if (from_sql&&to_sql){ connection.query(from_sql, function(error, rows, fields){if (error) socket.emit('error', error);}) connection.query(to_sql, function(error, rows, fields){if (error) socket.emit('error', error);}) io.sockets.emit('moveitemresult',player_id,itemlist_id,item_id,move_from,move_to,to_data ) } } } }); });