+Tequila Posted May 9, 2009 Share Posted May 9, 2009 And if so, what does the command look like? I would like to take my "emulator check", player name processing and a bunch of date/time checks and create a single Author Script to handle all of that. I need to be able to display messages such as "You can't play this cartridge in the Emulator" Is there a way to do that? Would really appreciate a code example. Thanks. Quote Link to comment
a_snail Posted May 9, 2009 Share Posted May 9, 2009 And if so, what does the command look like? I would like to take my "emulator check", player name processing and a bunch of date/time checks and create a single Author Script to handle all of that. I need to be able to display messages such as "You can't play this cartridge in the Emulator" Is there a way to do that? Would really appreciate a code example. Thanks. Author Script is identical to normal script, if you edit the lua file direct, you can move entire functions in there, however you would not then be able to access them through the normal builder interface, only through the author script. When I started, I would tend to use the builder to create the basics of something, then edit the lua file to see what the syntax was and copy out the bits of interest i.e. in this example you want to display a message, so if you create a message with some text; a message box with a picture; a message box with a button; etc, you can see the differences and how each is done. Refering back to the time question, if you paste the following code into the author script, then that will check the date is the 9th May 2009 and your not using the emulator, will do one thing otherwise do something else (in this case display two different messages). Just keep adding the ANDs for your other checks. theCurrentTime = os.date('!*t') if theCurrentTime.year == 2009 and month == 5 and day == 9 and Player.Name ~= "Builder" then Wherigo.MessageBox{Text=[[its OK to play today]],Buttons={"OK",},} else Wherigo.MessageBox{Text=[[You cant play this cartridge in the Emulator]],Buttons={"OK",},} end After the second MessageBox, but before the end, you could put the code to end the cartridge, but I forget what that is just at the moment. Note: identical comparison is a double equals; not equal to is a ~= Hope thats what your asking for Quote Link to comment
+Tequila Posted May 9, 2009 Author Share Posted May 9, 2009 It is what I am looking for but it does not seem to work. If I paste that into Author Script and run it, nothing happens. I even stripped it down to just a message box and still no message box. Would it be possible for you to post a source file here that works? Quote Link to comment
Ranger Fox Posted May 10, 2009 Share Posted May 10, 2009 Did you put the code into a function and call the function from somewhere? Quote Link to comment
a_snail Posted May 10, 2009 Share Posted May 10, 2009 (edited) Here is an example .lua file. Appologies for a few missing bits of code in the previous example, but now fixed and tested This can be viewed and editited in the normal builder, just highlight the date values and change them in the window that appears when you double click on When a cartridge is started require "Wherigo" ZonePoint = Wherigo.ZonePoint Distance = Wherigo.Distance Player = Wherigo.Player -- #Author Directives Go Here# -- -- #End Author Directives# -- cartcheck = Wherigo.ZCartridge() -- MessageBox Callback Functions Table used by the Builder -- cartcheck.MsgBoxCBFuncs = {} -- Cartridge Info -- cartcheck.Id="8eacdb25-4bea-4dac-bb08-9dcefd610c60" cartcheck.Name="check" cartcheck.Description=[[]] cartcheck.Visible=true cartcheck.Activity="TourGuide" cartcheck.StartingLocationDescription=[[]] cartcheck.StartingLocation = ZonePoint(51,-2,0) cartcheck.Version="" cartcheck.Company="" cartcheck.Author="" cartcheck.BuilderVersion="2.0.5129.5086" cartcheck.CreateDate="5/10/2009 7:24:58 AM" cartcheck.PublishDate="1/1/0001 12:00:00 AM" cartcheck.UpdateDate="5/10/2009 7:31:18 AM" cartcheck.LastPlayedDate="1/1/0001 12:00:00 AM" cartcheck.TargetDevice="PocketPC" cartcheck.TargetDeviceVersion="0" cartcheck.StateId="1" cartcheck.CountryId="2" cartcheck.Complete=false cartcheck.UseLogging=false -- Zones -- -- Characters -- -- Items -- -- Tasks -- -- Cartridge Variables -- -- Builder Variables (to be read by the builder only) -- buildervar = {} -- ZTimers -- -- Inputs -- -- -- Events/Conditions/Actions -- -- ------------------------------------------------------------------------------- ------Builder Generated functions, Do not Edit, this will be overwritten------ ------------------------------------------------------------------------------- function cartcheck:OnStart() -- #GroupDescription=test -- theCurrentTime = os.date('!*t') if theCurrentTime.year == 2009 and theCurrentTime.month == 5 and theCurrentTime.day == 10 and Player.Name ~= "Me" then Wherigo.MessageBox{Text=[[its OK to play today]],Buttons={"OK",},} else Wherigo.MessageBox{Text=[[You cant play this cartridge in the Emulator]],Buttons={"OK",},} end -- #Comment=test Comment -- end ------End Builder Generated functions, Do not Edit, this will be overwritten------ ------------------------------------------------------------------------------- ------Builder Generated callbacks, Do not Edit, this will be overwritten------ ------------------------------------------------------------------------------- --#LASTCALLBACKKEY=0#-- ------End Builder Generated callbacks, Do not Edit, this will be overwritten------ -- #Author Functions Go Here# -- -- #End Author Functions# -- -- Nothing after this line -- return cartcheck Alternatively, you can move the function to the author code and used the author view require "Wherigo" ZonePoint = Wherigo.ZonePoint Distance = Wherigo.Distance Player = Wherigo.Player -- #Author Directives Go Here# -- -- #End Author Directives# -- cartcheck = Wherigo.ZCartridge() -- MessageBox Callback Functions Table used by the Builder -- cartcheck.MsgBoxCBFuncs = {} -- Cartridge Info -- cartcheck.Id="8eacdb25-4bea-4dac-bb08-9dcefd610c60" cartcheck.Name="check" cartcheck.Description=[[]] cartcheck.Visible=true cartcheck.Activity="TourGuide" cartcheck.StartingLocationDescription=[[]] cartcheck.StartingLocation = ZonePoint(51,-2,0) cartcheck.Version="" cartcheck.Company="" cartcheck.Author="" cartcheck.BuilderVersion="2.0.5129.5086" cartcheck.CreateDate="5/10/2009 7:24:58 AM" cartcheck.PublishDate="1/1/0001 12:00:00 AM" cartcheck.UpdateDate="5/10/2009 7:31:18 AM" cartcheck.LastPlayedDate="1/1/0001 12:00:00 AM" cartcheck.TargetDevice="PocketPC" cartcheck.TargetDeviceVersion="0" cartcheck.StateId="1" cartcheck.CountryId="2" cartcheck.Complete=false cartcheck.UseLogging=false -- Zones -- -- Characters -- -- Items -- -- Tasks -- -- Cartridge Variables -- -- Builder Variables (to be read by the builder only) -- buildervar = {} -- ZTimers -- -- Inputs -- -- -- Events/Conditions/Actions -- -- ------------------------------------------------------------------------------- ------Builder Generated functions, Do not Edit, this will be overwritten------ ------------------------------------------------------------------------------- ------End Builder Generated functions, Do not Edit, this will be overwritten------ ------------------------------------------------------------------------------- ------Builder Generated callbacks, Do not Edit, this will be overwritten------ ------------------------------------------------------------------------------- --#LASTCALLBACKKEY=0#-- ------End Builder Generated callbacks, Do not Edit, this will be overwritten------ -- #Author Functions Go Here# -- function cartcheck:OnStart() -- #GroupDescription=test -- theCurrentTime = os.date('!*t') if theCurrentTime.year == 2009 and theCurrentTime.month == 5 and theCurrentTime.day == 10 and Player.Name ~= "Me" then Wherigo.MessageBox{Text=[[its OK to play today]],Buttons={"OK",},} else Wherigo.MessageBox{Text=[[You cant play this cartridge in the Emulator]],Buttons={"OK",},} end end -- #End Author Functions# -- -- Nothing after this line -- return cartcheck or, you could put the new code in a function and call it from a different function, but its still going to be red in the normal builder and confuse it slightly. Edited May 10, 2009 by a_snail Quote Link to comment
+Tequila Posted May 10, 2009 Author Share Posted May 10, 2009 (edited) To answer R/F's question, I was able to finally get the first sample working by putting the code in a function. However, I had to use the OnStart for the cartridge which meant I could not have an OnStart function in the normal builder code. I got both of the above samples to work the same way. While this works, it is not quite what I was hoping to be able to use. I was hoping to have a bunch of code in the Author Script that I could cut/paste into every cartridge that I develop without having to rewrite/modify the code each time. In the above case, the function OnStart has to be modified to account for the different cartridge name. Perhaps this is the best I can get. As you can no doubt see, my programming skills are pretty limited. Back to R/F's comment: If I call the function something other than OnStart, how would I call it from the Builder? Thanks for all your help AND patience. Edited May 10, 2009 by Tequila Quote Link to comment
a_snail Posted May 10, 2009 Share Posted May 10, 2009 To answer R/F's question, I was able to finally get the first sample working by putting the code in a function. However, I had to use the OnStart for the cartridge which meant I could not have an OnStart function in the normal builder code. I got both of the above samples to work the same way. While this works, it is not quite what I was hoping to be able to use. I was hoping to have a bunch of code in the Author Script that I could cut/paste into every cartridge that I develop without having to rewrite/modify the code each time. In the above case, the function OnStart has to be modified to account for the different cartridge name. Perhaps this is the best I can get. As you can no doubt see, my programming skills are pretty limited. Back to R/F's comment: If I call the function something other than OnStart, how would I call it from the Builder? Thanks for all your help AND patience. The example below might be what your after. If you want to just copy it to a load of cartridges, what you would do is copy the function in the author code, and then wherever you want to do a check, add in the line: CheckCartridgeIsOKToPlay() In the example below I've put it in OnStart, but it can go anywhere. The problem you are going to have is that the builder will not like any function with the CheckCartridgeIsOKToPlay() in it because its not something it knows about, so it will show it in author code. The best way to get round this I've found is to put it in a out of the way bit of Wherigo i.e the only thing that function is going to do is call CheckCartridgeIsOKToPlay e.g. 1. In response to a message box button been pressed (eg. as part of the welcome message) 2. as part of a timer event, although be careful about this one in case other things are happening and canel your message. Example Lua: require "Wherigo" ZonePoint = Wherigo.ZonePoint Distance = Wherigo.Distance Player = Wherigo.Player -- #Author Directives Go Here# -- -- #End Author Directives# -- cartcheck = Wherigo.ZCartridge() -- MessageBox Callback Functions Table used by the Builder -- cartcheck.MsgBoxCBFuncs = {} -- Cartridge Info -- cartcheck.Id="8eacdb25-4bea-4dac-bb08-9dcefd610c60" cartcheck.Name="check" cartcheck.Description=[[]] cartcheck.Visible=true cartcheck.Activity="TourGuide" cartcheck.StartingLocationDescription=[[]] cartcheck.StartingLocation = ZonePoint(51,-2,0) cartcheck.Version="" cartcheck.Company="" cartcheck.Author="" cartcheck.BuilderVersion="2.0.5129.5086" cartcheck.CreateDate="5/10/2009 7:24:58 AM" cartcheck.PublishDate="1/1/0001 12:00:00 AM" cartcheck.UpdateDate="5/10/2009 12:28:07 PM" cartcheck.LastPlayedDate="1/1/0001 12:00:00 AM" cartcheck.TargetDevice="PocketPC" cartcheck.TargetDeviceVersion="0" cartcheck.StateId="1" cartcheck.CountryId="2" cartcheck.Complete=false cartcheck.UseLogging=false -- Zones -- -- Characters -- -- Items -- -- Tasks -- -- Cartridge Variables -- -- Builder Variables (to be read by the builder only) -- buildervar = {} -- ZTimers -- -- Inputs -- -- -- Events/Conditions/Actions -- -- ------------------------------------------------------------------------------- ------Builder Generated functions, Do not Edit, this will be overwritten------ ------------------------------------------------------------------------------- function cartcheck:OnStart() CheckCartridgeIsOKToPlay() end ------End Builder Generated functions, Do not Edit, this will be overwritten------ ------------------------------------------------------------------------------- ------Builder Generated callbacks, Do not Edit, this will be overwritten------ ------------------------------------------------------------------------------- --#LASTCALLBACKKEY=0#-- ------End Builder Generated callbacks, Do not Edit, this will be overwritten------ -- #Author Functions Go Here# -- function CheckCartridgeIsOKToPlay() -- #GroupDescription=test -- theCurrentTime = os.date('!*t') if theCurrentTime.year == 2009 and theCurrentTime.month == 5 and theCurrentTime.day == 10 and Player.Name ~= "Me" then Wherigo.MessageBox{Text=[[its OK to play today]],Buttons={"OK",},} else Wherigo.MessageBox{Text=[[You cant play this cartridge in the Emulator]],Buttons={"OK",},} end -- #Comment=test Comment -- end -- #End Author Functions# -- -- Nothing after this line -- return cartcheck Quote Link to comment
a_snail Posted May 10, 2009 Share Posted May 10, 2009 PS Don't forget to change the player name from "Me" to "Builder" if your trying to prevent the emulator from being run. Quote Link to comment
+Tequila Posted May 10, 2009 Author Share Posted May 10, 2009 Thank you. That is exactly what I want. I assume you created the CheckCartridgeIsOKToPlay() call in the OnStart function with a text editor and not the Builder. Is that correct? Also, once I open the source in the Builder, I am able to open the OnStart code (it appears in red). Can I add code to it in the Builder? Thanks gain. Quote Link to comment
a_snail Posted May 10, 2009 Share Posted May 10, 2009 Thank you. That is exactly what I want. I assume you created the CheckCartridgeIsOKToPlay() call in the OnStart function with a text editor and not the Builder. Is that correct? Also, once I open the source in the Builder, I am able to open the OnStart code (it appears in red). Can I add code to it in the Builder? Thanks gain. Yes, I did use a text editor to add in the function into OnStart (I have to confess, I use the text editor for 95% of my building these days). Once the call to the function is in place, you will only be able to modify the source code directly (although you can do that in the builder), the builder will no longer help you construct the code, which is why I suggested putting that sort of call in a MessageBox button function earlier. Let me know if you need a demo of that. Quote Link to comment
+Tequila Posted May 10, 2009 Author Share Posted May 10, 2009 Thank you. That is exactly what I want. I assume you created the CheckCartridgeIsOKToPlay() call in the OnStart function with a text editor and not the Builder. Is that correct? Also, once I open the source in the Builder, I am able to open the OnStart code (it appears in red). Can I add code to it in the Builder? Thanks gain. Yes, I did use a text editor to add in the function into OnStart (I have to confess, I use the text editor for 95% of my building these days). Once the call to the function is in place, you will only be able to modify the source code directly (although you can do that in the builder), the builder will no longer help you construct the code, which is why I suggested putting that sort of call in a MessageBox button function earlier. Let me know if you need a demo of that. Yes, please post a demo. Demos are very good learning tools. One of the first emails I got from Ranger Fox suggested that I would reach a point where I would drift away from the Builder and start developing code in the text editor. Not only is R/F one helluva Wherigo illuminati, he is also a bit of a prophet. LOL Quote Link to comment
+sTeamTraen Posted May 10, 2009 Share Posted May 10, 2009 One of the first emails I got from Ranger Fox suggested that I would reach a point where I would drift away from the Builder and start developing code in the text editor. Not only is R/F one helluva Wherigo illuminati, he is also a bit of a prophet. LOL One of the design goals of Earwigo was to allow you to include arbitrary Lua code inline without having to abandon the point-and-click builder for the easy bits. Using a text editor is fine for code but not so much fun for regular data declarations. Quote Link to comment
a_snail Posted May 10, 2009 Share Posted May 10, 2009 One of the first emails I got from Ranger Fox suggested that I would reach a point where I would drift away from the Builder and start developing code in the text editor. Not only is R/F one helluva Wherigo illuminati, he is also a bit of a prophet. LOL One of the design goals of Earwigo was to allow you to include arbitrary Lua code inline without having to abandon the point-and-click builder for the easy bits. Using a text editor is fine for code but not so much fun for regular data declarations. I think its the cut and paste I like so much with the text editor and the fact that I can save the lua file in the text editor, load and run the script in the builder, find its taken out the builder or emulator and just undo the changes with out loosing all my work. Quote Link to comment
+Tequila Posted May 10, 2009 Author Share Posted May 10, 2009 a_snail, It took me all day to realize what you meant about putting the Author Script call in an obscure Message Box so that I wouldn't limit the ability of the Builder to help me create code. If I put the call in the OnStart function I can't use the Builder to develop more OnStart code. But, if I put it in a simple "Welcome to my Cartridge" message box, I can still use the Builder everywhere else. Takes awhile for things to sink in sometimes. Thanks for all your great help. Tequila Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.