Comparing Strings

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

zoot
Posts: 6
Joined: Thu Jul 29, 2004 3:15 am
Location: On the Level
Contact:

Comparing Strings

Post 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.

Guest

Post 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:

User avatar
Ice Cream Jonsey
Posts: 30193
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Post 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
the dark and gritty...Ice Cream Jonsey!

Post Reply