Jump to content

How do i get an integer variable to show up in a string?


HailHell

Recommended Posts

Natively?

newstring = oldstringprefix + iValue + oldstringsuffix

 

I ended up writing a string substitution script that would do the trick.

 

 

 

Scriptname JaxonzStringUtil
{string manipulation utility}

import StringUtil
import Debug

String Function StringSubst (String sOriginal, String sFind, String sReplace) global
;replace all occurrances of sFind in sOriginal with sReplace
	int iFoundLocation
	int iFindLen = GetLength(sFind)
	int iReplaceLen = GetLength(sReplace)
	int iFindReplaceLenDiff = iReplaceLen - iFindLen
	iFoundLocation = Find(sOriginal, sFind, iFoundLocation)
	While iFoundLocation > -1
		if iFoundLocation == 0	;a little weirdness here because asking Substring to return 0 length actually returns entire to string end
			sOriginal = sReplace + Substring(sOriginal, iFoundLocation + iFindLen)
		Else
			sOriginal = Substring(sOriginal, 0, iFoundLocation) + sReplace + Substring(sOriginal, iFoundLocation + iFindLen)		
		EndIf
		iFoundLocation = Find(sOriginal, sFind, iFoundLocation + iFindReplaceLenDiff)
	EndWhile
	
	return sOriginal
EndFunction 

 

 

 

That way you could just do:

Notification(StringSubst("You have # arrows left", "#", iNumArrows)

 

Would be great if we had a C version of this in StringUtil. It would be a simple passthrough to the native function and much faster.

 

Hope that helps.

Link to comment
Share on other sites

That sure looks complicated.... Glad I have no need to do that.

 

@HailHell

Assuming you already have an integer or float that tracks the # killed...

For the example we'll call that variable NumKilled.

 

Debug.Notification("You have killed this enemy "+NumKilled+" times.")

Link to comment
Share on other sites

If you're going to be reusing the same text and only want to change the numerical value, you can use message.show(Number)

 

http://www.creationkit.com/Show_-_Message

 

And format the message according to the flags on that page. In your case it would look like:

 

"You killed this enemy %.0f times."

 

Preferable in my opinion to putting the string in your script.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...