Why not click as my clicked object?

tablo = {}
local goput = require "main.goput"
local flatdb = require 'main.flatdb'
local basilimi
local kontrol
local kurulum_bool = false
local kontrol_string
local harf
local db
local anim_is_finish = false
local secilen_string = ""
local yazilacak_string = ""
local function handle_click(url, action_id, action)
	local abc  
	abc = string.sub(tostring(url), 12,31)
	abc = abc .. "#label"
	bu_url = string.sub(tostring(url), 31,31)
	if action_id == hash("touch") and kontrol==false then
		basilimi = true
		kontrol = true
		local yeni = string.sub(tostring(url), 12,31)
		table.insert(tablo, tonumber(bu_url),tostring(yeni))
		local xx = tostring(harf_table[tonumber(bu_url)]);
		yazilacak_string = yazilacak_string .. xx
		label.set_text("/four_boxes/go#label",yazilacak_string)
		kontrol_string = string.sub(yazilacak_string, 2,5)
	end
	if action.released and kontrol == true then
		print("Dokundu")
		basilimi = false
		kontrol  = false
		yazilacak_string = ""
		if soru == kontrol_string then
			print("Basarili")
			local lvl = db.page.seviye
			lvl = tonumber(lvl)
			lvl = lvl + 1
			db.page.seviye = lvl
			print(lvl)
			db:save()
			kurulum_bool = true
			kurulum(lvl)
		elseif kurulum_bool == false then
			go.set("#sprite", "tint", vmath.vector4(0.30, 0.30, 0.30,1))	
			go.animate("/four_boxes/harfler1", "rotation", go.PLAYBACK_ONCE_PINGPONG, vmath.quat_rotation_z(3.141592 / 4), go.EASING_INOUTEXPO, 1)
			go.animate("/four_boxes/harfler2", "rotation", go.PLAYBACK_ONCE_PINGPONG, vmath.quat_rotation_z(3.141592 / 4), go.EASING_INOUTEXPO, 1)
			go.animate("/four_boxes/harfler3", "rotation", go.PLAYBACK_ONCE_PINGPONG, vmath.quat_rotation_z(3.141592 / 4), go.EASING_INOUTEXPO, 1)
			go.animate("/four_boxes/harfler4", "rotation", go.PLAYBACK_ONCE_PINGPONG, vmath.quat_rotation_z(3.141592 / 4), go.EASING_INOUTEXPO, 1)
			go.set("/four_boxes/harfler1", "rotation", vmath.quat_rotation_z(0))
			go.set("/four_boxes/harfler2", "rotation", vmath.quat_rotation_z(0))
			go.set("/four_boxes/harfler3", "rotation", vmath.quat_rotation_z(0))
			go.set("/four_boxes/harfler4", "rotation", vmath.quat_rotation_z(0))	
			anim_is_finish = true
		end
	end
end

function anim_bitti()
	kurulum_bool = false
end
harf_table = {}

konu = ""
soru = ""
function kurulum(seviye)
	local data = sys.load_resource("/main/sorular.json")
	local layout_table = json.decode(data)
	local kelime = layout_table["Level_Dortlu"][seviye]["dizilis"]
	soru = layout_table["Level_Dortlu"][seviye]["soru"]
	konu = layout_table["Level_Dortlu"][seviye]["konu"]
	local sayi = string.len(kelime)
	label.set_text("/four_boxes/go#konu_label", konu)
	for i=1,4 do
		label.set_text("/four_boxes/harfler".. i .. "#label",string.sub(kelime, i, i))
		table.insert(harf_table, i,string.sub(kelime, i, i))
	end
	go.animate("/four_boxes/harfler1", "position.y", go.PLAYBACK_ONCE_BACKWARD, 6, go.EASING_INCUBIC, 1)
	go.animate("/four_boxes/harfler2", "position.y", go.PLAYBACK_ONCE_BACKWARD, 6, go.EASING_INCUBIC, 1)
	go.animate("/four_boxes/harfler3", "position.y", go.PLAYBACK_ONCE_BACKWARD, 6, go.EASING_INCUBIC, 1)
	go.animate("/four_boxes/harfler4", "position.y", go.PLAYBACK_ONCE_BACKWARD, 6, go.EASING_INCUBIC, 1,0,anim_bitti)
	go.set(".", "scale", vmath.vector3(0.13, 0.13, 0))

end

function init(self)
	db = flatdb('./db')
	if not db.page then
		db.page = {}
	end
	seviye = tonumber(db.page.seviye)
	seviye = 1
	db.page.seviye = 1
	db:save()
	kurulum(seviye)
	msg.post(".", "acquire_input_focus")
	--msg.post("@render:", "clear_color", { color = vmath.vector4(95 /256, 129 / 256, 161 / 256, 1 ) })
	self.tiklandimi = false
	basilimi = false
	kontrol = false
	go.set("#sprite", "scale", vmath.vector3(1.5, 1.5, 1))
	goput.add("#sprite", nil, handle_click)
end

function on_message(self, message_id, message)
	if message_id == hash("collision_response") and kontrol==true and self.tiklandimi == false then
		go.set("#sprite", "tint", vmath.vector4(0.15, 0.15, 0.5,3))
		self.tiklandimi = true
		kontrol = false
	end
end



function update(self, dt)
	if message_id ~= hash("collision_response") and kontrol == false and basilimi == false then
		self.tiklandimi = false
		go.set("#sprite", "tint", vmath.vector4(1, 1, 1,1))
	end
end

function final(self)
	msg.post(".", "release_input_focus")
	goput.remove("#sprite")

end

function on_input(self, action_id, action)
	return goput.on_input(action_id, action)
end

Can you please explain the problem a bit more? What is supposed to happen and what happens instead? And remember that your code contains a lot or non english (Turkish?) text that few here understands.

2 Likes



typed in other letters when I click

From your code it looks like you have one single rectangular sprite (#sprite) that you put an input handler on with the goput module.

But the screenshots show four letters, which I guess is not a single sprite? What are those letters? How is your code figuring out which letter the user is clicking?

2 Likes

I use collision response

1 Like

I do not understand. Can you please explain the following:

  1. What is the collision response on_message() code supposed to do?
  2. What is the on_click() function supposed to do?

The reason I ask is because you seem to approach this problem from two angles at the same time and I think you may have misunderstood both angles. So I wonder when you expect the code to run and what you expect it should achieve?

3 Likes