Page 1 of 1

Comparing Strings

Posted: Thu Jul 29, 2004 3:24 am
by zoot
Hi all,

I am having trouble getting my head around the way that Hugo handles arrays and strings. I want the user to enter a keycode, and then compare it to a pre-set string. Say my unlock code is "12345", what is the best way of dealing with this? I would expect my user to enter:

type "12345"

and then compare it to my reference. I have set up a custom routine for 'type', but no matter how I configure it, I can't get it to work.

The general code is as follows:

Code: Select all

	if location = lockerroom
	{
		if <entered code = stored code> !pseudo code!!!!

		&#123;
			"You have unlocked the door!"
		&#125;
		else
		&#123;
			"The keypad bleeps derisively as it rejects your code!"
		&#125;
	&#125;
	else
	&#123;
		"There is nothing to type on in here."
	&#125;
Any help, gratefully received.

Posted: Thu Jul 29, 2004 5:29 am
by Guest
Ok, I did it after reading the new "Book" - much better explanation, Kent, nice one :smile:

First, I defined a couple of arrays:

Code: Select all

array keycode&#91;6&#93;='1','2','3','4','5',0
array keyentered&#91;6&#93;='1','2','3','4','5',0
And now here is the "type routine"

Code: Select all

routine DoType
&#123;
	string&#40;keyentered,parse$,5&#41;
	if location = lockerroom
	&#123;
		
		if StringCompare&#40;keyentered,keycode&#41; = 0
		&#123;
			"Well done, you have unlocked the door!"
		&#125;
		else
		&#123;
			"The keypad bleeps derisively as it rejects your code!"
		&#125;
	&#125;
	else
	&#123;
		"There is nothing to type on in here."
	&#125;
	return true
&#125;
Getting there.... Maybe not the elegant way to do it, but it works :cool:

Posted: Thu Jul 29, 2004 9:10 am
by Ice Cream Jonsey
Excellent! Good to see that you got it working.

Also, welcome to the site! Questions usually get answered pretty quickly around here, I've found. If you get stuck on another Hugo bit let us know and we'll try it ourselves and see what's up.


Robb