Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

kelly1111 wrote: Thu Apr 06, 2023 8:38 pm Just testing something in chatgtp ...
What exactly did you ask ChatGPT?
Did it generate the code you posted?
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

Zo Kath Ra wrote: Thu Apr 06, 2023 4:59 pm
bongobeat wrote: Thu Apr 06, 2023 10:33 am it is in a single script file, without anything else, and linked to 2 buttons named mkbforge1 and mkbforge2

I'm asking because some players seems to have trouble with that, if the right combination is not found at first.
Maybe I have done something wrong here. This is just copy paste and modify from another script that someone made for me.
How does the puzzle work?

And how does the script work?
(if you can't answer this question, then that's the problem)

And what "trouble" are the players having?
It helps to be precise when reporting bugs...
The player has to look for the right combination in a room and then press accordingly the left button or the righ button (the hint are marqued as "L" or "R") and the button are placed left and right to the main hint.
They are related, in the script, to 1 or 2.

So when the player press a button, it enters "1" or "2" in the script, and then the script check if the good combination has been made.
Also the script is checking that only 2 buttons are linked to it and they should be named with whatever you want, but you need a number at last, 1 and 2.
If the wrong sequence is made, the script should reset itself that the next combination entered will be checked again, until the good one.


But regarding the players feedback, if you put the bad combination at first it seems that the script didn't reset properly.
They say if they doesn't do the right combination at the first time, they had to do it more than once then, even if (at the second time) the right combination has been made.

As I said that script is not my doing. Someone made me this script, can't remember who. And I use it a few time.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Banaora
Posts: 162
Joined: Wed Jun 05, 2013 9:39 am

Re: Ask a simple question, get a simple answer

Post by Banaora »

Maybe it is enough to enable sound feedback in the function combinationReset().

The way it is now you can enter "111222121211121" and it will not be accepted even though the string contains the correct solution because it will reset after the 3rd 1. And the player could wonder why that is when he doesn't get any kind of feedback.
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

Banaora wrote: Thu Apr 06, 2023 9:25 pm Maybe it is enough to enable sound feedback in the function combinationReset().

The way it is now you can enter "111222121211121" and it will not be accepted even though the string contains the correct solution because it will reset after the 3rd 1. And the player could wonder why that is when he doesn't get any kind of feedback.
You're probably right about the cause of the problem, and the solution.

But I think the original code is more complicated than it needs to be, so here's a simpler version.

Code: Select all

combination = "11222121211121"
count = 0 -- number of correctly guessed digits

function buttonCombination(callerButtonComponent)
	if count == #combination then
		hudPrint("The puzzle has already been solved!")
	elseif string.sub(callerButtonComponent.go.id, -1) == string.sub(combination, count + 1, count + 1) then
		-- last character in the pressed button's id == next digit in the combination
		count = count + 1
		if count == #combination then
			hudPrint("You have solved the puzzle!")
		end
	else
		hudPrint("Wrong button! The puzzle has been reset.")
		count = 0
	end
end
And here's a version that doesn't reset the puzzle, which is even simpler.

Code: Select all

combination = "11222121211121"
keypresses = ""

function buttonCombination(callerButtonComponent)
	keypresses = keypresses .. string.sub(callerButtonComponent.go.id, -1)
	if #keypresses > #combination then
		keypresses = string.sub(keypresses, 2)
	end
	
	if keypresses == combination then
		hudPrint("You have solved the puzzle!")
		-- deactivate the buttons
	end
end
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

Zo Kath Ra wrote: Thu Apr 06, 2023 11:03 pm
Banaora wrote: Thu Apr 06, 2023 9:25 pm Maybe it is enough to enable sound feedback in the function combinationReset().

The way it is now you can enter "111222121211121" and it will not be accepted even though the string contains the correct solution because it will reset after the 3rd 1. And the player could wonder why that is when he doesn't get any kind of feedback.
You're probably right about the cause of the problem, and the solution.

But I think the original code is more complicated than it needs to be, so here's a simpler version.

Code: Select all

combination = "11222121211121"
count = 0 -- number of correctly guessed digits

function buttonCombination(callerButtonComponent)
	if count == #combination then
		hudPrint("The puzzle has already been solved!")
	elseif string.sub(callerButtonComponent.go.id, -1) == string.sub(combination, count + 1, count + 1) then
		-- last character in the pressed button's id == next digit in the combination
		count = count + 1
		if count == #combination then
			hudPrint("You have solved the puzzle!")
		end
	else
		hudPrint("Wrong button! The puzzle has been reset.")
		count = 0
	end
end
And here's a version that doesn't reset the puzzle, which is even simpler.

Code: Select all

combination = "11222121211121"
keypresses = ""

function buttonCombination(callerButtonComponent)
	keypresses = keypresses .. string.sub(callerButtonComponent.go.id, -1)
	if #keypresses > #combination then
		keypresses = string.sub(keypresses, 2)
	end
	
	if keypresses == combination then
		hudPrint("You have solved the puzzle!")
		-- deactivate the buttons
	end
end
Will try that, thanks!
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Post Reply