Jump to content
  • 0

variable from mysql_query


DarkWolf

Question

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

15 answers to this question

Recommended Posts

  • 0

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
  • 0

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
  • 0

 

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
  • 0

Use table.getn instead booleans.

if table.getn(T4) > 0 then -- or table.getn(T4[1])
   say("values available")
else
   say("no values available")
end

when you return 0 and server doesn't boot:

unknown.png

Link to comment
  • 0

 

Use table.getn instead booleans.

if table.getn(T4) > 0 then -- or table.getn(T4[1])
   say("values available")
else
   say("no values available")
end

 

did not work, the quest goes out after i choose option YES

 

Link to comment
  • 0

Probably T4 is a nil value, try this:

 

if T4 ~= nil then
  say("values available")
else
  say("no values available")
end

 

  • Love 1

when you return 0 and server doesn't boot:

unknown.png

Link to comment
  • 0

But you tried using table.getn or checking if it was a nil value?

 

if T4[1] ~= nil then
  say("...")
else
  say("...2")
end

when you return 0 and server doesn't boot:

unknown.png

Link to comment
  • 0

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
  • 0

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
  • 0

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • 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.