Problem with LoadString at runtime

Monkey Forums/Monkey Programming/Problem with LoadString at runtime

Shinkiro1(Posted 2011) [#1]
Hello,

I load my level from an xml file and everything works as expected the first time.
Then I want change a value in the xml-file, save it and use the LoadString() command to reload the file.

monkey code
Import mojo

Class MyGame Extends App
	Field text:String
	
	Method OnCreate()
		SetUpdateRate 60
		text = LoadString("file.xml")
	End
	
	Method OnUpdate()
		If KeyHit(KEY_1)
			text = LoadString("untitled.xml")
			Print text
		End
	End
	
	Method OnRender()
		DrawText text, 0,0
	End
	
End

Function Main()
	New MyGame
End


file.xml
<this>
	<x>30</x>
</this>


Try to change something in the xml file, save it and press 1 in game.
Nothing will change.

Monkey will not reload the value until you completely restart your game.
Is this the wanted behaviour?


anawiki(Posted 2011) [#2]
Do you change the right XML file? The one in data folder is not the one that is loaded at runtime.


Jesse(Posted 2011) [#3]
are you building an HTML5?
if you are, you won't see any changes until you reload the page.


ziggy(Posted 2011) [#4]
Is this the wanted behaviour?
Yes, becouse some targets embed text files into the source code, so a recompilation is needed.


Shinkiro1(Posted 2011) [#5]
@anawiki: Thanks, totally forgot that.

Yes, becouse some targets embed text files into the source code, so a recompilation is needed.

I heard that ios doesn't allow scripting languages. But that doesn't mean you can't write your own (not native) scripting language?


Shinkiro1(Posted 2011) [#6]
Reloading at runtime in glfw works ... you just have to use this path instead of the data folder (on OSX):
projectname/projectname.build/glfw/xcode/build/Debug/MonkeyGame.app/Contents/Resources/data

In html5 as ziggy mentioned I think the data is embedded into the source file.


clevijoki(Posted 2011) [#7]
ios does allow scripting langauges, it was something they reversed. Many other cross platform development systems, like Corona SDK, use a scripting language. Apple just has a vendetta against flash for some reason.


hardcoal(Posted 2011) [#8]
Its good to know that in order to load a text file the file ending of the text file must be .txt

Ive being breaking my head yet for another hour just to figure that out err
what a waist


therevills(Posted 2011) [#9]
file ending of the text file must be .txt


Also xml and json works.

/docs/modules/index.html#/mojo.app/LoadString
Monkey will only load files that end with the following file extensions: .txt, .xml, .json.

Like all game data, text files must be saved in your project's .data folder or one of its sub-folders.



hardcoal(Posted 2011) [#10]
good to know tnx