How to declare a variable only once in Gamemaker Step function? - game-maker-studio-1.4

Screenshot
I want the variable maxx to only update once when calling this script and all the other lines of code every frame , please help

You could either:
Declare the variable in Create
Structure the script so that it is called in Create to initialize it and then in Step to use it
(an optional argument or lack of arguments for a reasonable solution, event_type for a hack)
Use variable_instance_exists provided that you are not using an ancient version of GMS1

Related

How do I add a member function as e.g. Boost Log filter?

I want to add a member function as a logging filter via:
boost::log::core::get()->set_filter(boost::phoenix::bind(&LoggerContext::checkIfShouldBeLogged, this, <WHICH_ARGUMENT_DO_I_PASS?>));
where the signature of the filtering function is
bool LoggerContext::checkIfShouldBeLogged(const boost::log::attribute_value_set &attributeValueSet);
just as described in the documentation.
I do not know which argument to pass from the function I am trying to add the filter in.
If I make that function static, I can simply omit the argument and set the filter like so:
boost::log::core::get()->set_filter(&LoggerContext::checkIfShouldBeLogged);
The argument seems to be passed magically.
Same goes for setting a custom formatter. The following works for a static function:
sink->set_formatter(&LoggerContext::fileFormatter);
with the signature
void LoggerContext::fileFormatter(boost::log::record_view const &rec, boost::log::formatting_ostream &strm);
But I again do not know where to get the arguments from in order to pass them, when using boost::phoenix::bind.
#Jorge Bellon: I just now read you comment, it gave me a good hint as to how this works.
The solution is to use the boost::phoenix placeholder. This works for both the formatter and the filter:
boost::log::core::get()->set_filter(boost::phoenix::bind(&LoggerContext::checkIfShouldBeLogged, this, boost::phoenix::placeholders::arg1));
sink->set_formatter(boost::phoenix::bind(&LoggerContext::fileFormatter, this, boost::phoenix::placeholders::arg1, boost::phoenix::placeholders::arg2));
Thank you for the tip!

Best Method to Manipulate a CfnParameter String in aws-cdk

I'm trying in vain to do this. Here is the scenario:
We are creating a CloudFormation Stack that will generate a CodePipeline, that will pull another stack definition from git and deploy it, using the CloudFormationCreateUpdateStackAction
The repo and branch etc. are provided as CfnParamaters and the subsequent stack name we would like to base off a concatenation of the repo name and branch name.
However in some cases the repo might be named with an underscore or other special character that is invalid for a stackName.
I've attempted to manipulate the parameter strings using Macro's but I didnt get anywhere near something useful and running a .replace() function on the repoStr.valueAsString property modifies the CDK's "Token" pointer, not the resulting paramter which is declared at runtime.
Any ideas?
There are two options I can see:
First is to read the actual parameter value at synthesis time, then you can use the .replace function on parameter value. https://docs.aws.amazon.com/cdk/api/latest/docs/#aws-cdk_aws-ssm.StringParameter.html#static-value-wbr-from-wbr-lookupscope-parametername
Second is to use CloudFormation intristic function to split the parameter and join the fragments back in allowed manner. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-split.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html

Can I create my own variable which should work like built in variable in Informatica

I want to create my own variable and want to set my default value which should work like a built in variable in Informatica. I want to use created variable in my all workflow.
Is it possible any way ?
Thanks
You can use the same parameter file across all of your mappings (there is syntax to separate out bits which are for specific sections and those which are universal by way of the scope) see following link https://network.informatica.com/thread/27560

How does one bypass SyntaxError when parsing code?

I am using openpyxl to read an excel file that will have changing values over time. The following function will take string inputs from the excel sheets to make frames for Tkinter.
def make_new_frame(strng, frame_location, frame_name, frame_list):
if not(frame_name in frame_list):
frame_list.append(frame_name)
exec("global %s" %(frame_name)) in globals()
exec("%s = Frame(%s)"%(frame_name, frame_location))
.... etc.
The code itself is quite long but I think this is enough of a snapshot to address my problem.
Now this results in the following error while parsing:
SyntaxError: function 'make_new_frame' uses import * and bare exec, which are illegal because it is a nested function
Everything in the code I included parsed and executed just fine several times, but after I added a few more lines in later versions in this function, it keeps spitting out the above error before executing the code. The error references the third line in the function, (which, I repeat, has been cleared in the past).
I added "in globals()" as recommended in another SO post, so that solution is not working.
There is a solution online here that uses setattr, which I have no idea how to use to create a widget without eventually using exec.
I would really appreciate if someone could tell me how to bypass the error while parsing or provide an alternative means for a dynamically changing set of frame names.
Quick Note:
I am aware that setting a variable as global in python is generally warned against, but I am quite certain that it will serve useful for my code
Edit 1: I have no idea why this was downvoted. If I have done something incorrectly, please let me know what it is so I can avoid doing so in the future.
I think this is an X/Y problem. You are asking for help with solution Y instead of asking for help on problem X.
If your goal is to create an unknown number of Frame objects based on external data, you can store references to the frame in a list or dictionary without having to resort to using exec and dynamically created variable names.
exec is a perfectly fine function, but is one of those things that you should never use until you fully understand why you should never use it.
Here's how to solve your actual problem without using exec:
frames = {}
def make_new_frame(strng, frame_location, frame_name, frames):
if not(frame_name in frames):
frames[frame_name] = Frame(frame_location)
return frames[frame_name]
With that, you now have a dictionary (frames) that includes a reference for every new frame by name. If you had a frame named "foo", for example, you could configure and pack it like this:
frames["foo"].configure(background="red", ...)
frames["foo"].pack(...)
If preserving the order of the frames is important you can use an OrderedDict.

How to declare functions in a custom global library in After Effects?

Is it possible to save all my custom expressions inside an external .jsx file, so I can call them from inside my projects?
For example, let's say I have an expression I use a lot, that ties a puppet tool point to a null object's position. I know I can I transform that expression into a function that could take, say, two arguments, but can I save it into a custom library, so that I can easily re-use it inside the project?
Right now, I'm simply copying and pasting the same code from property to property, and I'm beginning to feel there is an alternative way to do this more efficiently.
Thanks in advance!
I tested this with success, put this on top of your expression:
$.evalFile("/Users/myname/ae/functions.txt");
Then you can access whatever functions you have in your functions.txt file.
See here for more details: https://forums.creativecow.net/readpost/227/29337
The problem with this method is that you still need to include the extra line for each expression.
Anyway here is my complete setup, just in case: my expression is:
$.evalFile("/Users/myname/ae/functions.txt");
var p1 = thisComp.layer("Null 1").transform.position;
var p2 = thisComp.layer("Null 4").transform.position;
var p = p2 - p1;
printPosition(p)
And my functions.txt file contains the following:
function printPosition (p){
return " " + parseInt(p[0]) + " : " + parseInt(p[1])
}
A bit old question but I found a similar ling's solution without external files.
Add a null layer for your function
Add a marker and write your function on comment
Call eval on your comp->layer->marker->comment
When you want call your function you only need one line:
eval(thisComp.layer("FunctionLayer").marker.key(1).comment);
test(1);
I don't think that is possible.
But you can accomplish a lot by saving the expression as a preset (by dragging the actual layer property to the Effects & Presets window.
Note than you can the apply a preset to several layers by selecting them and using the Animation->Apply Animation Preset function
Hope that helps a little.