Variable or script argument to string?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Variable or script argument to string?

Post by Foxley »

I'm trying to write a script that sets a cost for each shop item (which are step-on NPCs) in my Zelda game but I'm not sure how to make HS do what I want it to.

Here's what I'm trying to do, I think it's pretty simple:

Code: Select all

script, check shop items, begin
	while (ref) do (
		next := next npc reference(ref)
		switch (npc id(ref)) do (
			case (20) set item price (30)
			case (22) set item price (60)
			case (24) set item price (20)
			case (28) set item price (50)
			case (29) set item price (60)
			case (30) set item price (75)
			case (34) set item price (90)
		)
		ref := next
	)
	subscript, set item price, cost, begin
		variable (str)
		str := create text
		
		$5=cost
		set slice text (str, 5)
		set parent (str, get npc slice(ref))
		put slice (str, 4, 20)
end
I honestly didn't expect it to work like that, but I'm also not sure how to make the "$5=cost" line work, can't find any documentation on it. That's the line that's throwing an error in hspeak though.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Nevermind, I did more searching through plotscript.xml and figured this out:

Code: Select all

subscript, set item price, cost, begin
		variable (str)
		str := create text
		
		$5="%d"
		string sprintf (5, 5, cost)
		set slice text (str, 5)
		set parent (str, get npc slice(ref))
		put slice (str, 2, 20)
	end
Result:
Image
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Looking great!

I like to write "string sprintf (5, $5="%d", cost)" as a slight shortcut.
Post Reply