Page 14 of 14

Re: New GUI scripting concepts and foundation

Posted: Wed Apr 03, 2013 8:47 pm
by Damonya
Thank you Jkos for the code. In fact you're right, but in testing the result is the same, the book takes up more space and is superimposed before dialogue, consequently the Yes/No dialog is only visible when you close the book. This is why it suited me, but I will test your solution.

EDIT : sorry but I can't run your code.

What is wrong here ?
SpoilerShow

Code: Select all

function autoexec()

	fw.setHook('test_book_1.gw_book_testing.onUseItem',function()
			local book = gw_book.create('test_book_1')
			
			book.onClose = function(closeButton)
			local s_text = [[Hey, you! Are you brave?]]
			local s_dlgId = Dialog.quickYesNoDialog(s_text, answerCallBack, nil)
			Dialog.activate(s_dlgId, answerCallback)
			gw.removeElement(closeButton:getAncestor().id) --this line removes the book from the gui
			end
			
			
			book.textColor = {100,100,100,210}
			book:addPageHeader(1,'This is the header of the 1st page.')
			
			
			book:addPageText(1,
[[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin iaculis pretium velit,
commodo molestie augue adipiscing ac. In hac habitasse platea dictumst.Maecenas massa diam, accumsan sed mattis in, volutpat non elit. Maecenas ut ullamcorper nisi.]]
)
		
			
			book:addPageImage(2,'mod_assets/grimwidgets/images/compass_full_E.tga',200,200)
			book:openPagePair(1)
			
		
			gw.addElement(book)
			return false
		end
	)

end

function answerCallBack(s_caption)
	if s_caption == "Yes" then
		hudPrint("Yeah, right...")
	end
	if s_caption == "No" then
		hudPrint("Run for your life! There's killer snail after you")
	end
end

Re: New GUI scripting concepts and foundation

Posted: Wed Apr 10, 2013 11:34 am
by Damonya
I have changed the script, it runs fine, but only the first time I play. If I save my game and load again the game, the script doesn't work anymore. I don't know why.


SpoilerShow

Code: Select all

function autoexec()

	fw.setHook('id_compass.id_script.onUseItem',function()

s_agree = "Lorem"	
s_challenge = "Dolor"

	local s_text = [[Lorem ipsum dolor sit amet]]

	local s_dlgId = Dialog.new(s_text, s_agree, nil) 
	Dialog.addButton(s_dlgId, s_challenge)
	Dialog.activate(s_dlgId, dCallBack)

	end
	)

end
	
	
function dCallBack(s_caption)

	if s_caption == s_agree then
		enigme_global:setValue(0)
		hudPrint("Lorem Ipsum")
	end
	
	if s_caption == s_challenge then
		enigme_global:setValue(1)
		hudPrint("dolor sit amet")
	end

end
In fact it's especially my dCallBack function that doesn't run after loads a game saving

I tried several other variations of this script but nothing works. Anyone have an idea? :|

EDIT : I tried a lot of other variation and I think the problem is in the Dialog.activate function that doesn't work as it should, I give up or I'll pull my hair out.

Re: New GUI scripting concepts and foundation

Posted: Wed Apr 10, 2013 5:42 pm
by JKos
Try defining
s_agree = "Lorem" anf
s_challenge = "Dolor"

as a "script entity variables"

Auteoexec is called only once and those variables are not saved (serialized) because they are defined inside of the autoexec function, so when you load the game those variables are undefined.
see: http://www.grimrock.net/modding/save-ga ... variables/

Code: Select all


s_agree = "Lorem"	
s_challenge = "Dolor"	

function autoexec()

	fw.setHook('id_compass.id_script.onUseItem',function()
	   local s_text = [[Lorem ipsum dolor sit amet]]

	    local s_dlgId = Dialog.new(s_text, script_name.s_agree, nil) 
	    Dialog.addButton(s_dlgId, script_name.s_challenge)
	    Dialog.activate(s_dlgId, script_name.dCallBack)

	end
	)

end


	
function dCallBack(s_caption)

	if s_caption == s_agree then
		enigme_global:setValue(0)
		hudPrint("Lorem Ipsum")
	end
	
	if s_caption == s_challenge then
		enigme_global:setValue(1)
		hudPrint("dolor sit amet")
	end

end
edit: and when you refer those variables from onUseItem-hook you have to use "full" name, eg. script_name.s_agree.
edit2: fixed and this should work also

Code: Select all

s_agree = "Lorem"   
s_challenge = "Dolor"   

function onUseItem()
      local s_text = [[Lorem ipsum dolor sit amet]]

       local s_dlgId = Dialog.new(s_text, s_agree, nil) 
       Dialog.addButton(s_dlgId, s_challenge)
       Dialog.activate(s_dlgId, dCallBack)
end

function autoexec()
   fw.setHook('id_compass.id_script.onUseItem',onUseItem)
end



   
function dCallBack(s_caption)

   if s_caption == s_agree then
      enigme_global:setValue(0)
      hudPrint("Lorem Ipsum")
   end
   
   if s_caption == s_challenge then
      enigme_global:setValue(1)
      hudPrint("dolor sit amet")
   end

end

Re: New GUI scripting concepts and foundation

Posted: Wed Apr 10, 2013 6:08 pm
by Damonya
I actually tried that but leaving everything in the same script_entity and the problem was that when I loaded again the game, it's whole script not working on OnUseItem event.

But I didin't know that :
Auteoexec is called only once and those variables are not saved (serialized) because they are defined inside of the autoexec function, so when you load the game those variables are undefined.
and you put me on the way. :)

With this, it runs now :

script_entity_1
SpoilerShow

Code: Select all

function autoexec()

   fw.setHook('id_compass.script_entity_1.onUseItem',function()


   local s_text = [[Lorem ipsum dolor sit amet]]

   local s_dlgId = Dialog.new(s_text, "Lorem", nil)
   Dialog.addButton(s_dlgId, "Dolor")
   Dialog.activate(s_dlgId, script_entity_2.dCallBack)

   end
   )
script_entity_2
SpoilerShow

Code: Select all

s_agree = "Lorem"   
s_challenge = "Dolor"


function dCallBack(s_caption)

	if s_caption == s_agree then
		enigme_global:setValue(0)
		hudPrint("Lorem Ipsum")
	end
	
	if s_caption == s_challenge then
		enigme_global:setValue(1)
		hudPrint("Dolor sit amet")
	end

end

EDIT : ok you edited your post since. And I will test your solution

Thanks a lot :D

EDIT2 : Ok I have tested. With your first solution, it works, but with your second solution, same problem when you loaded again the game, with the complete script not working on OnUseItem event, but it does not matter now, because we have found 2 other solution. Thanks.