Registered Member
|
I am trying to write a comic engine. I know there is standing offer to make such engines, but I would prefer to do it myself. That being said, I am having some difficulty. I think it may be a problem with my regular expressions. How exactly do I handle the "reference any character" (the period) and "reference any digit" (d) items? Is it just . or \. and is it just d or is it \d? The use of a literal period also seems to be inconsistent. I know the regular expressions work with an ecmascript tester, but then the xkcd engine seems to use a different syntax that does not work. Also, does match[1] match the first () or does it match the whole thing?
Here is an example:
I am trying to match a file of the form: z#.png or z#.gif, where # is a number with 1-4 digits (if the number is less than 100 it is zero-padded to 3 digits). What I actually want is the number itself, so I am trying to get this by matching the first parenthesis. Is this going to do what I expect? Is there any way to test to see where the problems in my code are occuring?
Last edited by TheBlackCat on Sun Jan 18, 2009 9:37 pm, edited 1 time in total.
Man is the lowest-cost, 150-pound, nonlinear, all-purpose computer system which can be mass-produced by unskilled labor.
-NASA in 1965 |
KDE Developer
|
There you go:
This means: - 'z' character - a match of a digit repeated a number of times between 1 and 4 (both included) - a literal dot - one of 'png' or 'gif' The usage of (ie quoting) is needed when writing strings in languages like C/C++/JavaScript, as you want to write literally a '' in the string. Also, you need to quote the dot in the regexp, otherwise it would mean "any character" (as you wrote). About the final matching... I don't remember regexps much in JS, but usually 0 means "the whole match", 1 the first group and so on. Keep also in mind alternatives (ie "(png|gif)") are groups too, so you can know which alternative was actually matched. Last tip: you can use KRegExpEditor (KDE 3 application available in kdeutils) to test you regexps.
Pino Toscano
|
KDE Developer
|
I am not exactly commenting on that RegExp part, as pino already did that and as the following website would explain that probably a lot better (even with examples) than I would: http://www.w3schools.com/jsref/jsref_obj_regexp.asp and http://www.w3schools.com/JS/js_obj_regexp.asp (introduction)
In general you should have a similar structure for all the files like the other plugins on kde-files.org If you have created a plugin and want to test it simply type
in a terminal and then
Now choose your comic and look if it works or if you get any error messages in the console output. If you don't get any output and it does not work, then open the main file from
and add something like:
This way you can judge what does work and what not, I'm always using something like "****" in the prints as it is easier to spot and search for in the output, you could use whatever you like. Then if everything works remove all the lines with print and save the main file where you originally stored it, create the package and upload it. You also need to "deinstall" (remove) your manually installed comic.
After all that you will find it in the get hot new stuff dialog, though sometimes that can take a while.
Last edited by mat69 on Sat Jan 24, 2009 10:57 pm, edited 1 time in total.
mat69, proud to be a member of KDE forums since 2008-Oct.
|
Registered Member
|
#@%$. After so many hours trying to find the problem I was just missing a period in two of my "comic.identifier" calls. Thanks for the help, it seems to be working now.
Last edited by TheBlackCat on Sun Jan 25, 2009 2:00 am, edited 1 time in total.
Man is the lowest-cost, 150-pound, nonlinear, all-purpose computer system which can be mass-produced by unskilled labor.
-NASA in 1965 |
Registered Member
|
I seem to be having another weird problem now. It seems "function pageRetrieved(id, data)" is only running for the first comic. If I browse back and forth to other comics this function does not seem to be called. If I browse back to the first comic manually it also does not seem to be called. But if I do "Go to current comic" that function is called again. I can't figure out why.
Man is the lowest-cost, 150-pound, nonlinear, all-purpose computer system which can be mass-produced by unskilled labor.
-NASA in 1965 |
KDE Developer
|
Yeah I know that feeling, happened to me very often as well, but now with all the prints I find problems relatively fast. Sometimes when I was "blinded" to find the problem I ended with a lot of print statements like print("****a"); ranging to print("*****g") etc.
That is because that these comics have been cached allready, if you visit a comic you have not visited before than pageRetrieved will be called. In general it works that way for the comic dataengine:
A comic is cached if there is a nextIdentifier. In some cases though you do not need to specifiy previousIdentifier and nextIdentifier yourself if the comics are identified by ...
To test your plugin you should go to
and no comics are cached anymore you can not turn caching off though, so as soon as you look at a comic that has a nextIdentifier then it will be cached. I'm sorry that there is no documentation, have to do that. I also hope that everything I posted out of my head is correct.
Last edited by mat69 on Sun Jan 25, 2009 2:58 pm, edited 1 time in total.
mat69, proud to be a member of KDE forums since 2008-Oct.
|
Registered Member
|
I see, caching must be doing it. Thanks!
What is the initial comic.identifier if you do not specify a lastidentifier up front? Also, how will the engine handle updates to the comic while the comic engine is still open? Does it re-do the "init" part periodically?
Last edited by TheBlackCat on Sun Jan 25, 2009 5:06 pm, edited 1 time in total.
Man is the lowest-cost, 150-pound, nonlinear, all-purpose computer system which can be mass-produced by unskilled labor.
-NASA in 1965 |
Registered Member
|
I figured out my first question, but I still am not sure about the second. If the comic is updated but the person does not logout, how will the comic engine now?
Last edited by TheBlackCat on Sun Jan 25, 2009 5:40 pm, edited 1 time in total.
Man is the lowest-cost, 150-pound, nonlinear, all-purpose computer system which can be mass-produced by unskilled labor.
-NASA in 1965 |
KDE Developer
|
Currently it won't know that. It only provides the data it was asked for and if nothing exactly was specified (like "garfield:" --> your first question) it will ask for a comic from 1. today 2. # 0 3. empty string Though I have to admit I'm not really satisfied with that way. Imho it would be better to seperate that like having "bool wantsMostRecent" or whatever, but a change like that should also work with any plugins and versions of the dataengine. Otherwise it would be a pita to support plugins for 4.2 and 4.3+. But back to your original question: The comic applet itself tells the data engine when to update it. In the applet there is a timer that checks if the day changed and if that happens the comic is reloaded. Probably I'll also add an option like "check each X minutes for new comics", better worded in fact.
Last edited by mat69 on Sun Jan 25, 2009 7:40 pm, edited 1 time in total.
mat69, proud to be a member of KDE forums since 2008-Oct.
|
Registered Member
|
Good, daily checks will work nicely. Your "check every X amount of time" idea is good, it might also be good to add an option to check at a certain time on certain days of the week, for a comic like XKCD that updates with a fixed schedule. Being able to specify the default checking behavior within the comic engine might also be worthwhile, since the one writing the engine should know if there is a regular update schedule.
Will there be, or is there already, support for comics that are split up across multiple image files? http://www.captainsnes.com/ and http://www.schlockmercenary.com/ both do this.
Man is the lowest-cost, 150-pound, nonlinear, all-purpose computer system which can be mass-produced by unskilled labor.
-NASA in 1965 |
KDE Developer
|
I'm not sure if that is really needed. And if that was added problems with timezones could occur if not everybody would use UTC. I think reloading the current strip all X minutes would do the job as well, especially as that only needs download if the strip is not cached already. In fact reloading would be only done if there is a connection or if the status of the connection is unknown.
Yes there is. Currently Deo Ignito uses that, also ****! to some degree. Best is you look at the way I did it in the first as I could not say that out of my head. Though ignore all the "compatility" settings, those are only needed in this specific case as here comics are mixed with news on the website sometimes --> have to make that a more generic way. Ok, looking at it: 20-21: global variables created 54-64: an array of pictures is created 86: first image is downloaded and removed of the array 115-123: the rest of the images is downloaded and combined
mat69, proud to be a member of KDE forums since 2008-Oct.
|
KDE Developer
|
OK, I created a tutorial on how to create comic plugins. You can find a link to it here: creating-comic-plu ... 29950.html
Last edited by mat69 on Sun Feb 01, 2009 10:54 pm, edited 1 time in total.
mat69, proud to be a member of KDE forums since 2008-Oct.
|
Registered Member
|
Any additional questions should probably go in the tutorial thread instead of here, so I will close this thread.
Man is the lowest-cost, 150-pound, nonlinear, all-purpose computer system which can be mass-produced by unskilled labor.
-NASA in 1965 |
Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell