Cole Chapman Posted August 14, 2011 Share Posted August 14, 2011 I am trying to figure out what the best way is to import a user made script into a blitzmax application. I want the application to be able to work with new scripts even after a build so I was thinking of something like (Main.bmx) - pseudocode Readfile "Scriptfile.scr" If Readfile contains "Start" Then Start() Endif Function Start() Local I:int = 800 Local y:int = 600 'Ect' EndFunction Reading the file and seeing if it contains keywords for functions and then executing functions. If anyone else has any better ideas though, feel free to help me out Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 14, 2011 Share Posted August 14, 2011 Yeah, that will work, and it's faster than using some bloated Lua or Python parser, because they contain 90% features you don't need for your game. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Cole Chapman Posted August 14, 2011 Author Share Posted August 14, 2011 Very cool! thanks man Quote Link to comment Share on other sites More sharing options...
Paul Thomas Posted August 15, 2011 Share Posted August 15, 2011 An interesting concept, Cole. I've thought about something similar but every time I do I end up trying to create a new language, which gets complex, and never finished, lol. My only input is to keep it simple and that you should do a better search than just "Start," maybe "Start()." There is also a module (Bah.Regex) you can use for regular expressions. Quote Link to comment Share on other sites More sharing options...
Cole Chapman Posted August 15, 2011 Author Share Posted August 15, 2011 Definately, but with things requiring some variables I may keep the option open for not using parentheses. For example: MovePlayerToPlayer(Player1, Player2) or MovePlayerToPlayer Player1, Player2 I could then splice the string to get things before and after the comma. Ill be sure to check out the Regex module Quote Link to comment Share on other sites More sharing options...
Paul Thomas Posted August 15, 2011 Share Posted August 15, 2011 I've attached the Regex module, just in case you want to try it out. I also played a bit with your idea: myscript.scr StartAI() MovePlayerToPlayer() MovePlayerToPlayer(Player1, Player2) Start() End() Terminate(1) script.bmx SuperStrict Import bah.regex Import brl.standardio Local file:TStream = ReadFile(AppDir+"/myscript.scr") Local regex:tregex = tregex.Create("(.*)\((.*)\)") While Not Eof(file) Local match:tregexmatch = regex.find(Trim(ReadLine(file))) If match Select Lower(match.subexp(1)) Case "startai" StartAI() Case "moveplayertoplayer" Local vars:String[] If match.subexp(2) <> "" vars = match.subexp(2).split(", ") MovePlayerToPlayer(vars[0], vars[1]) Else MovePlayerToPlayer() EndIf Default If match.subexp(2) = "" Print "No Match: "+match.subexp(1) Else Print "No Match: "+match.subexp(1)+"("+match.subexp(2)+")" EndIf EndSelect EndIf Wend CloseStream(file) Function StartAI() Print "Do something with AI" EndFunction Function MovePlayerToPlayer(p1:String = "", p2:String = "") If p1 <> "" Or p2 <> "" Print "move "+p1+" to "+p2 Else Print "Do something with player move with no arguments." EndIf EndFunction This will output: Do something with AI Do something with player move with no arguments. move Player1 to Player2 No Match: Start No Match: End No Match: Terminate(1) Actually having fun with this on this rainy day. Anyways, figured I'd just throw all of that out there. bah.regex.rar Quote Link to comment Share on other sites More sharing options...
Cole Chapman Posted August 16, 2011 Author Share Posted August 16, 2011 Very cool! i was messing around with string.contain stuff but the regex subexp stuff comes in handy. Quote Link to comment Share on other sites More sharing options...
Paul Thomas Posted August 20, 2011 Share Posted August 20, 2011 How is this going, Cole? Quote Link to comment Share on other sites More sharing options...
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.