Maybe i'm going about this wrong, and if i am please tell me because i just dont know any better.
But i am trying to pass in a CCString into the following format, and not having any luck. Could someone please tell me what the parameter for strings would be in C++ when passing them into another string?
Code:
CCString tilt = "";
if (recalculatedFrames >= 4 && (numberOfTimesRun > 0 && numberOfTimesRun < recalculatedFrames - 1)) {
tilt = "TR_";
}
initalTurnAnimationFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(CCString::stringWithFormat("%s%d.png", tilt, i)));
Also is it fine to make a blank string like i am doing with tilt?
I think tilt should be class of string
And the CCString part should be
CCString::createWithFormat("%s%d.png", tilt.c_str(), i);
try this
CCString::stringWithFormat("%s%d.png", tilt.getCString(), i)
Related
I try to learn how to use openSCAD. I 'm reading (also watching) a lot of tutorials but I cannot get why the following code does not work. Could you please help me?
difference() {
polygon(
points=[[2,0],[1.6,2.6],[2.2,3.4],[5.6,4],[11.4,3.4],[11.4,0.6],[10,-1.6],[7.6,-2.4],[4.4,-1.8]]);
polygon(// right len holder in
points=[[2.4,0],[2,2.6],[2.5,3.1],[5.6,3.6],[11,3],[11,0.6],[9.8,-1.2],[7.6,-2],[4.4,-1.45]]);}
your top level object is a 2D-object, use linear_extrude to get 3D-objects:
h = 10;
difference() {
linear_extrude(height=h) polygon(
points=[[2,0],[1.6,2.6],[2.2,3.4],[5.6,4],[11.4,3.4],[11.4,0.6],[10,-1.6],[7.6,-2.4],[4.4,-1.8]]);
linear_extrude(height=h) polygon(// right len holder in
points=[[2.4,0],[2,2.6],[2.5,3.1],[5.6,3.6],[11,3],[11,0.6],[9.8,-1.2],[7.6,-2],[4.4,-1.45]]);
}
I'm building a simple calculator for a classroom, this is the code to show the result:
- (void)doTheMathForPlus:(float)val {
float conto = self.contBox + val;
self.myDisplay.text = [NSString stringWithFormat:#"%.02f", conto];
}
I need to know if "conto" have decimals (to change the format of the string in a if statement)
how to do it?
thanks
if (conto == (int)conto) {
}
Hope this helps.
you'd better wrap that with #define and put this line in your .pch file
#define HAS_DECIMALS(x) (x!=(int)x)
than use anywhere in the code:
if (HAS_DECIMALS(conto)) {
//number has decimals
} else {
//number does not have decimals
}
Yes, dredful is right with his answer.
And, You also can use different functions like floor, ceil, round. In You case better "floor(conto)".
But, you can't do like Kyr Dunenkoff suggested. becouse, all operands for"%" should be integer, but not float as "conto".
When i typed [lat1 = newLocation.coordinate.latitude]; its telling expected : before ] token like that. whats my fault? as i am new to this domain., please ayone guide me.
Thanks In Prior....
If you are trying to compare lat1 and newLocation.coordinate.latitude, the correct statement would be:
if (lat1 == newLocation.coordinate.latitude) {
// do something here
}
If you are trying to assign the value of newLocation.coordinate.latitude into lat1, the correct statement is:
lat1 = newLocation.coordinate.latitude;
If you are trying to do the first thing and the compared variables are floating point numbers, then you probably want to check if they are close enough instead of equality:
if (fabs(lat1 - newLocation.coordinate.latitude) < someLittleDistance) {
// close enough
}
…where of course you will have to define someLittleDistance.
Try the following..
Remove the [] brackets from your line it must be
lat1 = newLocation.coordinate.latitude;
When xCode behaves like this, it probably wants to say that something is the method or it thinks of something like a method. Dot-notation in Objective-C as usual is some kind of equivalent of the setter. For example
ObjectA.property1 = value;
is equivalent of
[ObjectA setProperty1:value];
And in the last case, xCode expects to see : after the setter call and a value after the column.
This seems so basic but for some reason I can't get it to work - the 2 variables are both defined as NSIntegers:
if ([AScore == "100"] && [BScore == "100"]) {
...
}
That doesn't work - nor does it work when I take away the parentheses - nor does it work if I try to implement the 'isEqualToString' command. I'm sure this is a very basic mistake that i am making.
NSIntegers aren't objects, nor are strings integers.
Use if(AScore == 100 && BScore == 100) { instead.
I am having a strange problem with boolean logic. I must be doing something daft, but I can't figure it out.
In the below code firstMeasure.isInvisibleArea is true and measureBuffer1 is nil.
Even though test1 is evaluating to NO for some reason it is still dropping into my if statement.
It works ok if I use the commented out line.
Any idea why this happens?
BOOL firstVisible = firstMeasure.isInVisibleArea;
BOOL notFirstVisible = !(firstMeasure.isInVisibleArea);
BOOL measureBufferNil = measureBuffer1 == nil;
BOOL test1 = measureBuffer1 == nil && !firstMeasure.isInVisibleArea;
BOOL test2 = measureBufferNil && !firstVisible;
if (measureBuffer1 == nil && !firstMeasure.isInVisibleArea)
//if (measureBufferNil && !firstVisible)
{
//do some action
}
Update 1:
I isolated the problem to !firstMeasure.isInVisibleArea as I've entirely taken on the measureBuffer bit.
Inside isInVisible area is a small calculation (it doesn't modify anything though), but the calculation is using self.view.frame. I am going take this out of the equation as well and see what happens. My hunch is that self.view.frame is changing between the two calls to isInVisibleArea.
Update 2:
This is indeed the problem. I have added the answer in more detail below
When in doubt, you should fully parenthesize. Without looking up the precedence rules, what I think what is happening is that = is getting higher precedence than == or &&. So try:
BOOL test1 = ((measureBuffer1 == nil) && !firstMeasure.isInVisibleArea);
While you certainly can parenthesize, you should also know that nil objects evaluate to boolean NO and non-nil objects evaluate to boolean YES. So you could just as easily write this:
BOOL firstVisible = firstMeasure.isInVisibleArea;
BOOL notFirstVisible = !(firstMeasure.isInVisibleArea);
BOOL measureBufferNil = measureBuffer1;
BOOL test1 = !measureBuffer1 && !firstMeasure.isInVisibleArea;
BOOL test2 = measureBufferNil && !firstVisible;
if (measureBuffer1 && !firstMeasure.isInVisibleArea) {
//do some action
}
You would end up with the same results. I agree with GoatRider, though. It's always far better to parenthesize your conditional expressions to clarify what you really want to happen than it is to rely on the language's operator precedence to do it for you.
If test1 is evaluating to NO as you say, then drop test1 into the if statement:
if(test1){
//see if this executes?
}
See what that does.
My hunch was correct, it is related to the view frame changing between calls to firstMeasure.isInVisible area.
This whole routine is called in response to the view moving. I think I need to grab the value of firstMeasure.isInVisibleArea at the start of the method and use that value throughout.
Phew. Boolean logic isn't broken. All is right with the world.
Thanks for all your input