Strange results when using SELECT in a function #5

Closed
opened 2021-04-05 13:45:30 +00:00 by bloggy · 12 comments
bloggy commented 2021-04-05 13:45:30 +00:00 (Migrated from github.com)

I get <none> on the first run and the correct value on the second run of my script, which is very strange. Maybe you can tell me what's happening here.
A broadcast within the function will always display the correct value on the first run.
With first run and second run I mean entering the command "/test".

Versions:

  • This server is running Tuinity version git-Tuinity-"94f025a" (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT)
  • Loading Skript v2.5.3
  • [skript-db] Loading skript-db v1.2.1

The script:

function testing(p: player) :: number:
	set {_uuid} to {_p}'s uuid
	execute "SELECT uuid, player, points FROM `mytable` WHERE `uuid` = %{_uuid}%;" in {sql} and store the result in {_r::*}
	set {_points} to {_r::points::1}
	# This will return the correct value!
	#broadcast "Points: %{_points}%"
	return {_points}


command /test:
	trigger:
		set {_p} to the player
		set {_result} to testing({_p})
		# This will return the wrong value (it will return <none> on the first run, and the correct value on the second run)!
		message "Final: %{_result}%"

Table Structure (Screenshot):
https://i.imgur.com/p9Vh15W.png

How can this happen? How to fix?

I get `<none>` on the first run and the correct value on the second run of my script, which is very strange. Maybe you can tell me what's happening here. A broadcast within the function will always display the correct value on the first run. With first run and second run I mean entering the command "/test". **Versions:** - This server is running Tuinity version git-Tuinity-"94f025a" (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT) - Loading Skript v2.5.3 - [skript-db] Loading skript-db v1.2.1 - **The script:** ``` function testing(p: player) :: number: set {_uuid} to {_p}'s uuid execute "SELECT uuid, player, points FROM `mytable` WHERE `uuid` = %{_uuid}%;" in {sql} and store the result in {_r::*} set {_points} to {_r::points::1} # This will return the correct value! #broadcast "Points: %{_points}%" return {_points} command /test: trigger: set {_p} to the player set {_result} to testing({_p}) # This will return the wrong value (it will return <none> on the first run, and the correct value on the second run)! message "Final: %{_result}%" ``` **Table Structure (Screenshot):** https://i.imgur.com/p9Vh15W.png How can this happen? How to fix?
GovindasOM commented 2021-04-05 13:46:30 +00:00 (Migrated from github.com)

it is because you cannot use delayed effects in return functions, execute is delayed

it is because you cannot use delayed effects in return functions, execute is delayed
ham1255 commented 2021-04-05 13:48:46 +00:00 (Migrated from github.com)

Why execution is delayed here?

Why execution is delayed here?
bloggy commented 2021-04-05 13:49:25 +00:00 (Migrated from github.com)

Thank you for your quick reply.
Same question:

  • Why would execute be delayed? Reason for this?
  • What would be the best to fix it?
Thank you for your quick reply. Same question: - Why would execute be delayed? Reason for this? - What would be the best to fix it?
GovindasOM commented 2021-04-05 13:49:55 +00:00 (Migrated from github.com)

Thank you for your quick reply.
Same question:

* Why would execute be delayed? Reason for this?

* What would be the best to fix it?

it is delayed to not lag the server, the queries are ran on separate thread

> Thank you for your quick reply. > Same question: > > * Why would execute be delayed? Reason for this? > > * What would be the best to fix it? it is delayed to not lag the server, the queries are ran on separate thread
GovindasOM commented 2021-04-05 13:50:37 +00:00 (Migrated from github.com)

in future version I will make "synchronous execute" to also be asynchronous, but converting the current code to async, thus avoiding delay, so maybe that'll be able to solve the issue partially

in future version I will make "synchronous execute" to also be asynchronous, but converting the current code to async, thus avoiding delay, so maybe that'll be able to solve the issue partially
bloggy commented 2021-04-05 13:53:46 +00:00 (Migrated from github.com)

So that means for now I am unable to use return values that come from SELECT statements in a skript function?

So that means for now I am unable to use return values that come from SELECT statements in a skript function?
GovindasOM commented 2021-04-05 13:57:36 +00:00 (Migrated from github.com)

yes, that's the case with all similar add-ons, a workaround is skript-reflect's delayed effect

yes, that's the case with all similar add-ons, a workaround is skript-reflect's delayed effect
bloggy commented 2021-04-05 14:02:03 +00:00 (Migrated from github.com)

And what about this situation:

Can it happen that when I send two EXECUTE commands one right after the other, the result of the second event is not displayed correctly to me?

Example:

execute "INSERT INTO {@table} (`uuid`, `player`, `points`) VALUES (%{_uuid}%, %{_playername}%, %{_points}%) ON DUPLICATE KEY UPDATE `player` = %{_playername}%, `points` = %{_points}%" in {sql}
execute "SELECT uuid, player, points FROM `{@table}` WHERE `uuid` = %{_uuid}%;" in {sql} and store the result in {_r::*}

Could the SELECT result then be empty the first time because the INSERT INTO wasn't fast enough for the SELECT to receive the new value?

Regarding skript-reflect's delayed effect: it may be inconsistent as well, or not? Because you never know how long to wait?

And what about this situation: Can it happen that when I send two EXECUTE commands one right after the other, the result of the second event is not displayed correctly to me? Example: ``` execute "INSERT INTO {@table} (`uuid`, `player`, `points`) VALUES (%{_uuid}%, %{_playername}%, %{_points}%) ON DUPLICATE KEY UPDATE `player` = %{_playername}%, `points` = %{_points}%" in {sql} execute "SELECT uuid, player, points FROM `{@table}` WHERE `uuid` = %{_uuid}%;" in {sql} and store the result in {_r::*} ``` Could the SELECT result then be empty the first time because the INSERT INTO wasn't fast enough for the SELECT to receive the new value? Regarding skript-reflect's delayed effect: it may be inconsistent as well, or not? Because you never know how long to wait?
GovindasOM commented 2021-04-05 14:03:24 +00:00 (Migrated from github.com)
  1. it should be consistent and shouldn't have any issues, mysql should handle it well

  2. you know how long to wait, wait until a value is returned (which is when the code continues after EXECUTE)

1. it should be consistent and shouldn't have any issues, mysql should handle it well 2. you know how long to wait, wait until a value is returned (which is when the code continues after EXECUTE)
bloggy commented 2021-04-05 14:04:56 +00:00 (Migrated from github.com)

Could you by any chance post an example of such a skript-reflect "delay" syntax?

Could you by any chance post an example of such a skript-reflect "delay" syntax?
GovindasOM commented 2021-04-05 14:05:28 +00:00 (Migrated from github.com)

sadly I do not have an example, but if I remember correctly, you just type:
delay the effect or something like that

sadly I do not have an example, but if I remember correctly, you just type: ```delay the effect``` or something like that
GovindasOM commented 2021-04-12 13:30:02 +00:00 (Migrated from github.com)

I am closing this issue as this is intended and not a bug

I am closing this issue as this is intended and not a bug
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Limework/skript-db#5
No description provided.