[Resolved] Trouble with combinations

Hey,

So I have to do this:

The user have 2 steps: for the first one, he choose from 1 of 12 objects. In the second, one of 9 images. When he chooses one object in the first scene, it goes to the second one, and then the same happens for the final scene with the results.

Is there a way to set something like

if object1 and image1 then resultx
if object2 and image 4 then resultx
?
[import]uid: 95495 topic_id: 24215 reply_id: 324215[/import]

You’d have two variables and call them, for example, obj1 and obj2.

You’d likely give the objects names when adding them, eg;
object1.name = “turtle”
(Just pretend object 1 is a picture of a turtle in this case.)

When they select the first object make obj1 = whatever they picked.

Same for obj2.

Then;

if obj1.name == “turtle” and obj2.name == “whatever” then
– do stuff here
end

Does that make sense? [import]uid: 52491 topic_id: 24215 reply_id: 97884[/import]

Yes, it makes sense!

Does anything need to be global, since I’m working with different scenes?

Thanks Peach! [import]uid: 95495 topic_id: 24215 reply_id: 97915[/import]

If using Director then yes, you may want to make obj1 and obj2 global.

Obviously you want to avoiding using globals when you can though, it shouldn’t be regular practice. Some people strongly discourage it in all cases whereas I’m of the mind that the odd one here and there is OK. (Matter of opinion only.)

If you want to avoid global you could save the info to a file and load it on the final screen.

Peach :slight_smile: [import]uid: 52491 topic_id: 24215 reply_id: 98169[/import]

Hey Peach, I did it…thanks!

Is there a way to, instead of selecting one of my objects, dragging it to the middle of the screen, and then set it’s flag = true? (that’s how I made it: if \_G.image1 == true and object2 == true then

FOr instance, I have my image 1, set here:

image1 = display.newImageRect("image1.png", 50,50); image1:setReferencePoint(display.CenterReferencePoint) image1.x = \_W/2 ; image1.y = \_H/4 image1.scene = "objectscene" local function imagepress(event) if event.phase == "ended" then director:changeScene(event.target.scene) \_G.image1flag = true end end image1:addEventListener("touch", imagepress);

How do I set it to be dragged to the middle (if it reaches somewhere near the middle and the user releases, it goes to _W/2, _H/2), and then the flag = true and the scene changes?

Thanks a lot Peach… [import]uid: 95495 topic_id: 24215 reply_id: 98996[/import]

You can get drag code from all over but basic drag code is like this;

[lua]local function drag(event)
obj.x, obj.y = event.x, event.y
end
obj:addEventListener(“touch”, drag)[/lua]

For checking it you’d add an if statement, eg;

if event.phase == “ended” and event.x > 100 and event.x < 200 and event.y > 200 and event.y < 300 then
–do stuff

That’s very rough but just to give you an example.

Make sense?

Peach :slight_smile: [import]uid: 52491 topic_id: 24215 reply_id: 99068[/import]

Hi Peach, it makes sense. But I’m having trouble in where to add this statement

Should it be something like: [code]

local ball = display.newImageRect(“btn.jpeg”, 100, 100)
ball:setReferencePoint(display.CenterReferencePoint)
ball.x = _W/2; ball.y = 0 + (ball.height/2 + 20);
ball.name = “ball”;

local function drag(event)
if event.phase == “moved” then
ball.x, ball.y = event.x, event.y
end
if event.phase == “ended” and event.x > 100 and event.x < 200 and event.y > 200 and event.y < 300 then
ball.x = _W/2; ball.y = _H/2
end
ball:addEventListener(“touch”, drag)[/code]

With this code, it moves fine while dragging, but doesn’t go to the middle when released! [import]uid: 95495 topic_id: 24215 reply_id: 100783[/import]

Add a print statement so you can see the ball x and y while dragging it.

Your code says the X should be between 101 and 199 and they y should be between 201 and 299, so that isn’t the middle on an iPhone. (As I said my coords were just an example, you should modify them.)

Let me know how that goes :slight_smile:

Peach [import]uid: 52491 topic_id: 24215 reply_id: 100947[/import]

Ok, I see it now and it is working!

One question though: in different devices, the middle pixel spot changes…for instance, iphone 3GS is 160, 240 and iPhone 4 320, 480 and so on…in the simulator, my config doesn’t seem to adjust to this changes, and what once was the middle becomes the top left quarter of the screen. How do I do that? [import]uid: 95495 topic_id: 24215 reply_id: 100998[/import]

It will work, it scales up so the middle will still know it’s the middle.

It’s like when you put an object at x = 160 and y = 240 it will be in the center on a 3GS, right?

Well if you run that same app on an iPhone 4 it will still be in the middle so long as you’ve set scale to letterbox, zoomEven, etc.

Make sense? :slight_smile: [import]uid: 52491 topic_id: 24215 reply_id: 101175[/import]

Hi Peach, it makes perfect sense.

I managed to make it work. I have one question though:

When I drag an image and it passes through the other image at the same scene, it sorts of drags the second one along, like I clicked in that one too. But it is in the move phase really.

How do I solve that? [import]uid: 95495 topic_id: 24215 reply_id: 101257[/import]

Make sure you are setting the focus. (Drag sample code shows this, so does MultiPuck I believe.) [import]uid: 52491 topic_id: 24215 reply_id: 101452[/import]

Hum, I’m not sure how to do that…, the sample code you mean is where? [import]uid: 95495 topic_id: 24215 reply_id: 101571[/import]

Open CoronaSDK folder on your computer.

Then SampleCode > Physics > MultiPuck

I believe that has it, else try other sample code that includes drag :slight_smile: [import]uid: 52491 topic_id: 24215 reply_id: 101591[/import]

Hm, I found a couple of samples including this one, but all of them add body to the images and they collide while dragging. What I want is simply to one image ignore the other one exists while it’s been dragged…it just needs to passé through it without activating the other ones function. Can it be done? [import]uid: 95495 topic_id: 24215 reply_id: 101597[/import]

Yes, using set focus - I thought we did that in that sample code.

OK, this sample code DEFINITELY uses setFocus;

CoronaSDK > SampleCode > Interface > DragMe

:slight_smile: [import]uid: 52491 topic_id: 24215 reply_id: 101752[/import]