Jump to content

variable from mysql_query


Go to solution Solved by DarkWolf,

Recommended Posts

Hi guys,

 

I'm trying to make a quest where the variable value comes from  mysql_query  but it isn't working like i want, can someone help please?

 

 

Here's the quest:

quest test2 begin
	state start begin
		function flag()
			local qf = mysql_query("SELECT flag_value FROM player.flag WHERE available='YES' LIMIT 1")
			return qf
		end
		when 20351.chat."test2" begin
			say_title(mob_name(npc.get_race())..":")
			say("")
			say("you want the flag?")
			say("")
			local x = select("YES","NO")
			if x == 2 then
				return
			elseif x == 1 then
				local T2 = "test2.flag()"
				game.set_event_flag(T2, 1)
				return
			end
		end
	end	
end

the problem is,  "teste2.flag()"  from local T2 it's assumed like a flag, but it  is not what i want, i want the vaule who can out from flag() function its given to the flag of game.set_event_flag.
 

 

 

Thanks, hope someone can help.

Link to comment
Share on other sites

  • Developer

You're trying to set a table as event flag's name. When you are running the SELECT function on a query, it'll always return a table.

function flag()
    local gf = mysql_query("SELECT flag_value FROM player.flag WHERE available='YES' LIMIT 1")
    return tostring(gf[1][1])
end

when ... begin
    game.set_event_flag(test2.flag(), 1)
end
  • Love 1

when you return 0 and server doesn't boot:

unknown.png

Link to comment
Share on other sites

 

You're trying to set a table as event flag's name. When you are running the SELECT function on a query, it'll always return a table.

function flag()
    local gf = mysql_query("SELECT flag_value FROM player.flag WHERE available='YES' LIMIT 1")
    return tostring(gf[1][1])
end

when ... begin
    game.set_event_flag(test2.flag(), 1)
end

 

thank you PACIFICADOR it's working.

 

but now i have a new problem, i want to check if still available values in the table, i tried with this but not work:

quest test4 begin
	state start begin
		function value_check(a)
			local check = mysql_query("SELECT available FROM player.value WHERE availableP1='"..a.."'")
			return true
		end
		when 20351.chat."test4" begin
			say_title(mob_name(npc.get_race())..":")
			say("")
			say("You want check the value?")
			say("")
			local x = select("YES","NO")
			if x == 2 then
				return
			elseif x == 1 then
				local T4 = test4.value_check("YES")
				if T4 == true then
					say_title(mob_name(npc.get_race())..":")
					say("")
					say("values available.")
					say("")
					return
				else
					say_title(mob_name(npc.get_race())..":")
					say("")
					say("No values available.")
					say("")
					return
				end
			end
		end
	end	
end

If i put all as NO in the table it still says "values available."

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

I think it works well

quest test2 begin
    state start begin
	
        when 20351.chat."test2" begin
            say_title(mob_name(npc.get_race())..":")
            say("")
            say("you want the flag?")
            say("")
            if select("YES","NO") == 1 then
				local var = mysql_query("SELECT flag_value FROM player.flag WHERE available='YES' LIMIT 1")
				if var == nil or (var[1] or {})[1] == nil then chat("null var") return end
                game.set_event_flag(var[1][1], 1)
                return
            end
        end
		
    end
end
Link to comment
Share on other sites

Try this one:

quest test4 begin
    state start begin
        function value_check(a)
            local check = mysql_query("SELECT * FROM player.value WHERE availableP1='"..a.."'")
            if check.available[1] == "YES" then
				return true
			else
				return false
			end
        end
        when 20351.chat."test4" begin
            say_title(mob_name(npc.get_race())..":")
            say("")
            say("You want check the value?")
            say("")
            local x = select("YES","NO")
            if x == 2 then
                return
            elseif x == 1 then
                local T4 = test4.value_check("YES")
                if T4 == true then
                    say_title(mob_name(npc.get_race())..":")
                    say("")
                    say("values available.")
                    say("")
                    return
                else
                    say_title(mob_name(npc.get_race())..":")
                    say("")
                    say("No values available.")
                    say("")
                    return
                end
            end
        end
    end
end

  • Love 2
Link to comment
Share on other sites

Try this one:

quest test4 begin
    state start begin
        function value_check(a)
            local check = mysql_query("SELECT * FROM player.value WHERE availableP1='"..a.."'")
            if check.available[1] == "YES" then
				return true
			else
				return false
			end
        end
        when 20351.chat."test4" begin
            say_title(mob_name(npc.get_race())..":")
            say("")
            say("You want check the value?")
            say("")
            local x = select("YES","NO")
            if x == 2 then
                return
            elseif x == 1 then
                local T4 = test4.value_check("YES")
                if T4 == true then
                    say_title(mob_name(npc.get_race())..":")
                    say("")
                    say("values available.")
                    say("")
                    return
                else
                    say_title(mob_name(npc.get_race())..":")
                    say("")
                    say("No values available.")
                    say("")
                    return
                end
            end
        end
    end
end

 

It doesn't work, quest goes out after i choose option YES

Link to comment
Share on other sites

  • Solution

I solved it!

 

here it is:

quest test4 begin
    state start begin
        function value_check(a)
            local check = mysql_query("SELECT * FROM player.value WHERE availableP1='"..a.."'")
			return check
        end
        when 20351.chat."test4" begin
            say_title(mob_name(npc.get_race())..":")
            say("")
            say("You want check the value?")
            say("")
            local x = select("YES","NO")
            if x == 2 then
                return
            elseif x == 1 then
                local T4 = test4.value_check("YES")
                if table.getn(T4) > 0 then
                    say_title(mob_name(npc.get_race())..":")
                    say("")
                    say("values available.")
                    say("")
                    return
                else
                    say_title(mob_name(npc.get_race())..":")
                    say("")
                    say("No values available.")
                    say("")
                    return
                end
            end
        end
    end
end

Thanks to everyone! :)

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.