I did not think this would work!

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

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

I did not think this would work!

Post by Ice Cream Jonsey »

I have code that lets you reload a gun in combat. By default, the game says

N)ew magazine

Well, that doesn't work when the weapon is a shotgun. I have a shotgun_type defined, so I was going to have the game say

N)ew round of shells

When the weapon to be reloaded was a shotgun. Except that the bean bag gun shoots bean bags, but it has shotgun_type

I ended up trying this, which I did not think would work:

Code: Select all

	if ItemsArray[fighter.equippedWeapon] is shotgun_type
	{
		"N)ew round of ";
		print ItemsArray[fighter.equippedWeapon].ammo_type.name
	}
I didn't think you could reference the name of the ammo_type like that. For some reason, I thought that Hugo would stop you once you had, essentially, "the first dot." But it didn't!

So that is cool and made me happy.
the dark and gritty...Ice Cream Jonsey!

Roody_Yogurt
Posts: 2255
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Re: I did not think this would work!

Post by Roody_Yogurt »

Yeah, this can be pretty useful. I usually add parentheses, though, just in case I'm grouping the properties in an order that the engine doesn't expect:

Code: Select all

print (ItemsArray[fighter.equippedWeapon].ammo_type).name

Post Reply