Simple draggable fan demo

This code has been superceded by the newer, working version:
http://developer.anscamobile.com/code/simple-draggable-fan-demo-2

Hi,

I’ve wanted to give something back to the community for a while, so I’ve written a little sample of a positionable fan which you can turn on/off and move around.

It is far too messy to submit to the code exchange pages, but I wanted to let people know about it as the core of the math is straightforward and should be easily extractable.

You can download the full thing here: https://files.me.com/horacebury/q42ff6

Let me know what you think :slight_smile:

I promise I’ll tidy it up and submit it proper (when work-load allows!)

Cheers,

Matt. [import]uid: 8271 topic_id: 2993 reply_id: 302993[/import]

This is cool, Matt! I got it to work once, but then it kept giving me errors as I moved the “fan” around…
table: 0x366b10
Runtime error
… Dev/Corona/Corona Game SampleCode/WindTest/main.lua:75: attempt to call method ‘removeSelf’ (a nil value)
stack traceback:
[C]: in function ‘removeSelf’
… Dev/Corona/Corona Game SampleCode/WindTest/main.lua:75: in function <… dev game samplecode>
?: in function <?:214>
[import]uid: 9905 topic_id: 2993 reply_id: 9558[/import] </…>

Hey thanks, I really appreciate the feedback.

The error is thrown because, apparently, the table variable ‘hypline’ does not have a ‘removeSelf()’ function, however I don’t understand why as the only construction of the ‘hypline’ variable is performed using the ‘display.newLine()’ function. Unless I’m missing something, at some point the ‘hypline’ variable must be replaced by some other object. As you can see in the code, just before the ‘removeSelf()’ is called the variable is printed, always with a non-nil table reference.

If you discover what is causing it to fail in calling the ‘removeSelf()’ I would be very grateful to know. I’m sure it is something typical I may be taking for granted. [import]uid: 8271 topic_id: 2993 reply_id: 9587[/import]

i did a print

[lua]if (hypline ~= nil) then
print(“TouchMove”)
print(tostring(hypline))
print(type(hypline))
hypline:removeSelf()
end[/lua]

all other times the TouchMove function calls once

[lua]hypoteneuse: 127
power: 25
sum: 152
radius: 152
fraction: 1.1968503937008
width: -88.000030517578 height: 92.550109863281
powerx: 142.67712882936 powery: 295.76863542692
x: 248 y: 185
TouchMove
table: 0x6702c0
table

hypoteneuse: 141
power: 11[/lua]

but just before the error it’s calling twice

[lua]hypoteneuse: 141
power: 11
sum: 152
radius: 152
fraction: 1.0780141843972
width: -98.000030517578 height: 101.55010986328
powerx: 152.3545770307 powery: 285.47245885971
x: 258 y: 176
TouchMove
table: 0x6708e0
table
TouchMove
table: 0x6708e0
table
Runtime error
…ojects/Corona/Downloaded Code/Misc/WindTest/main.lua:78: attempt to call method ‘removeSelf’ (a nil value)
stack traceback:
[C]: in function ‘removeSelf’
…ojects/Corona/Downloaded Code/Misc/WindTest/main.lua:78: in function <…ojects code>
?: in function <?:214>[/lua]

hope this helps
j [import]uid: 6645 topic_id: 2993 reply_id: 11056[/import] </…ojects>

Reposting for reference from another thread:

https://files.me.com/horacebury/yht96y

The share had died.

m [import]uid: 8271 topic_id: 2993 reply_id: 24734[/import]

Thanks, will check it out =) [import]uid: 9577 topic_id: 2993 reply_id: 24928[/import]

I tried the file, and when i contain error
it run ok on the first run, then i closed the apps.
Then the error occur.

‘removeSelf’
Runtime error

anyone got this to work? [import]uid: 36507 topic_id: 2993 reply_id: 35358[/import]

Hello,

To fix it add

hypline = nil

after the line

hypline:removeSelf()

[import]uid: 8366 topic_id: 2993 reply_id: 35367[/import]

Thanks guys.

When I wrote this code I was pretty new to the whole lua thing and I’ve not fixed it for the download.

It does make a nice learning curve for those trying it out though… [import]uid: 8271 topic_id: 2993 reply_id: 35377[/import]

Thanks and I got it to work.
I was wondering if this can work toward 1 direction

Cause the wind blow from 1 directoion to the other.
Any thoughts on making this happen. [import]uid: 36507 topic_id: 2993 reply_id: 35416[/import]

Just adjust the x and y inputs to the applyForce call. For the y just make it 0 and for the x just check the it has the correct +/-. Maybe add some code to make it +ve if it’s -ve when you want west to east wind. [import]uid: 8271 topic_id: 2993 reply_id: 35424[/import]

I know I am late to the party on this topic, but I could use a small push on this. What am I looking for in this demo? I see the fan strength in the terminal, but don’t see anything moving on the screen. Do I need to add a small object?

Sorry for being obtuse (and late)…

David [import]uid: 71572 topic_id: 2993 reply_id: 48995[/import]

The fan should push the crate around, if you drag the centre of the fan about. [import]uid: 8271 topic_id: 2993 reply_id: 50190[/import]

you really have to up the force to get the crate to move.

try hard coding the force and drag the fan close to the crate, with the fan on the left side on the crate.

crate:applyForce( 125,125 , crate.x,crate.y ) [import]uid: 11860 topic_id: 2993 reply_id: 67076[/import]

Hey very interesting Matt (And I was calling you Horace!!!). A nice use of forces and physics!! Rest assured I’m scooping up all your examples and filing them away for future use! :slight_smile: Keep 'em coming, they’re much appreciated!

-Mario [import]uid: 11636 topic_id: 2993 reply_id: 76638[/import]

fixed the nil issue and tried different applyForce but still doesn’t work. The crate simply falls on the ground and despite moving the fan, nothing happens. Any idea? [import]uid: 12109 topic_id: 2993 reply_id: 89849[/import]

Sorry for the wait guys, but I’ve uploaded a new sample code which effectively replaces the original fan demo:

http://developer.anscamobile.com/code/simple-draggable-fan-demo-2 [import]uid: 8271 topic_id: 2993 reply_id: 90231[/import]