Comparing Strings

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:smile: :sad: :eek: :shock: :cool: :-x :razz: :oops: :evil: :twisted: :wink: :idea: :arrow: :neutral: :mrgreen:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Comparing Strings

by Ice Cream Jonsey » Thu Jul 29, 2004 9:10 am

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

by Guest » Thu Jul 29, 2004 5:29 am

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[6]='1','2','3','4','5',0
array keyentered[6]='1','2','3','4','5',0
And now here is the "type routine"

Code: Select all

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

Comparing Strings

by zoot » Thu Jul 29, 2004 3:24 am

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.

Top