Eval on Processing.js - eval

and thanks for taking the time to look at my question.
I'm still a beginner (relatively, a few months of experience) at programming, and I'm trying to make a simple game in processing. I want to have an eval function so that I can evaluate some typed in strings. This is just a simple game, so security isn't a problem, and I don't mind if certain things that get typed in will create unusable code because the code inputted will only be creating new shapes and not messing with existing code. I tested out the eval function by doing this.
eval("background(0);")
but the background obstinately stays white. Am I doing something wrong? (as I suspect) This is my first time dealing with evals.
Thanks for you help!

I can confirm that the eval("background(0);") approach does not work for Firefox, IE or Chrome. background(0); does work. Maybe you can work around this by taking apart the string and looking at the specific information there. I was able to do this with the followin example:
<!DOCTYPE html>
<html>
<body>
<script src="processing.js"></script>
<script type="application/processing">
size(600,600);
var str = "background(100);";
if (str.indexOf("background")==0){ //does the string start with "background"
str = str.replace( /\D+/g, '');//number extraction found on http://stackoverflow.com/questions/10003683/javascript-get-number-from-string
background((int)str); //use just the number
text(str,10,20);
}
</script><canvas></canvas>
</body>
</html>

Related

UE4 Grenade deal damage

I have a grenade BP which the hero throws and wondering how you would set this up ..
I have tried and works fine but this way is caused by a sphere collision and checks what is inside the collision during detonation.
I tried without casting but this didn't work out very well for me, Is there something else I should be doing?
Please ignore the "get overlapping actors" class filter, I only done that as a test, i usually leave it blank.
ideally id like to try some sort on line trace when the bomb detonates so it can check if its a direct hit rather than triggering even when safe behind cover.
Any help is greatly appreciated, thank you!
Is there casting necessary? say I had 10 other different AI characters, id have to cast through them all right
I tried without casting but this didn't work out very well for me, Is there something else I should be doing?
Please ignore the "get overlapping actors"class filter, I only done that as a test, i usually leave it blank
I found out using a MultiSphereTraceByChannel works much better.

Putting year() directly into a array

I am currently creating a array that holds a bunch of different data. One of the data points is to hold the most recent date accessed. For some reason I can't put year() into the array without the program breaking. Code below.
world_saves.push([[year()]]);
What's the reasoning behind this, and how do I set put the year into the array without a error. I've tried defining year() into a variable, but once again I get a error. Error below.
World_Data.js:5 Uncaught ReferenceError: year is not defined
Thanks in advance!
EDIT:
For anyone viewing this, this is the correct code to use.
var pjs = new Processing();
world_saves.push([[pjs.year()]]);
With the caveat that I've never used processing.js, it appears that you have to instantiate an instance of it first before calling methods on it.
Something like:
var pjs = new Processing();
world_saves.push([[pjs.year()]]);
also note: You do realize you're pushing an array of an array containing the year here, right? (vs. just world_saves.push(pjs.year());)
I see that you already got this sorted out, but just for your information: with Processing.js, typically you'd write Processing code and have Processing.js create the Processing instance and call the setup() and draw() functions for you. There are a ton of ways to do this (many are outline on this page), but the basics would look like this:
<script src="processing-1.3.6.min.js"></script>
<script type="application/processing" data-processing-target="pjs">
int[] worldSaves = new int[1];
void setup() {
size(200, 200);
worldSaves[0] = year();
}
void draw(){
background(0);
text(worldSaves[0], 10, 10);
}
</script>
<canvas id="pjs"> </canvas>
What you came up with isn't really wrong or anything, but I also don't know why you're using Processing.js if you aren't using the Processing part of it. So eventually you might end up with something more like the above.

Structure members break, when accompanied with brackets

Example:
.. member:: CK_UTF8CHAR model[16]
Gives me both the type and the name bolded and hyperlink not working.
Practically we are forced to use this cases like that:
.. member:: model
Because otherwise it would be incorrect (use it without array and with the same type).
Well, this seems to be a real bug in Sphinx. I reported that and it was confirmed. I've come up with a little workaround for now, but it's more of a crutch. Just put the following to the layout.html file of your Sphinx theme:
<script>
$('dl.member dt').each(function() {
$(this).find('big:first').text('[')
$(this).find('big:last').text(']')
});
</script>
Now you may use parenthesis instead of brackets in broken structures: model(16) becomes model[16] (and label(\ ) becomes label[], but only within the .. member:: directive.
I know it is not a very elegant solution, but it is OK as a temporary fix, until the bug gets resolved.

drawing with libcairo

I try to draw with libcairo, it draws nothing. I downloaded the diagram sample, it works fine [draw.c], but code example from the site doesn't draw: like http://cairographics.org/samples/fill_and_stroke2/
why?
Thanks!
The code you linked to looks fine. But of course, it's not a complete program. Without seeing what code you've wrapped around the example to make it run, all I can guess is that you may need to call cairo_show_page() and cairo_surface_flush().

google plus one button statistics

I would like to know how to get the value for the +1 value((if there are 10 clicks +1 button, store 10 as a variable). This would be helpful for analysis purposes.
I know the count parameter is only Boolean or plusone.state returns on/off but is there something like plusone.value? ( i tried it, it's undefined)
Thanks
Download the following url: https://plusone.google.com/u/0/_/+1/fastbutton?count=true&url=URLENCODED_URI via your favorite automatic method (curl, wget, file_get_contents, etc...)
URLENCODED_URI is the site you which to know the number of +1's for, e.g. http://www.google.com
For example, fetch the URI https://plusone.google.com/u/0/_/%2B1/fastbutton?count=true&url=http://www.google.com/ and locate the first occurance of window.__SSR = {'c': 32414.0 ,'si'. Preferably use regexp for this, but I'll leave the implementation to you and your chosen programming language.
The float number following 'c' is the number of +1's the site have. For google.com this is 32.414. Don't worry about it being a float, it is allways an integer in float format, so you can safely convert it to an integer.
There is an undocumented API for this described here - http://www.tomanthony.co.uk/blog/google_plus_one_button_seo_count_api/
Directions for +1 button tracking can be found at http://yoast.com/plus-one-google-analytics/
On the button creation screen, create a js callback then track the clicks using Google analytics with the following code:
<script type="text/javascript">
function plusone_vote( obj ) {
_gaq.push(['_trackEvent','plusone',obj.state]);
}
</script>
Alternately, use the javascript callback to track it any way you wish.

Resources