I am a novice at Corona, and I’m trying to make it so that at random intervals between 1 and 3 seconds, little objects will appear above the screen and will have a linear velocity of 500 going downwards. However, the simulator just shows black and terminal says there was a syntax error: “function arguments expected near ‘=’”
Here is my code:
[code]
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0 )
–Function to create objects up top
local ballSpawn = function()
Btw, 300 or 500 is a little fast to see on screen.
Plus, your spawn logic is flawed. timer.performWithDelay function runs only once, so it only generates one random number, say 1.5 and all objects will spawn with 1.5 seconds intervals.
To solve this, you may want to put your timer function inside the spawn function, and put 1 as last parameter
you should also keep the last line but change its last parameter to 1 too, it will trigger the spawn function for the first time, then spawn function recursively call itself with random intervals.
note: you should change your function definition to
local function ballSpawn()
in order to work this way. Otherwise timer call inside the function does not work. [import]uid: 46529 topic_id: 14452 reply_id: 53491[/import]
I tried this, but I am still having the same syntax error, and the screen of the simulator is showing black. Just to be sure I’m doing this right, here’s my new code:
[code]
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0 )
–Function to create objects up top
local function ballSpawn()
ok it seems everybody who gave an answer lost his mind. I didn’t look the ninjapigs’ answer so I couldn’t tell his mistake, also Lewis overlooked the mistake.
setLinearVelocity is a function, you call a function by adding “()” to the name of the function not “=”.
So you should change your code to :
ball:setLinearVelocity( 0, 300 )
there will be no “=” sign after function name. [import]uid: 46529 topic_id: 14452 reply_id: 53660[/import]
@ninjapig123, it is such a small mistake but it is so funny you overlook it and give advice to check api list. [import]uid: 46529 topic_id: 14452 reply_id: 53663[/import]
I replaced my current code with this code you gave me, and now I’m getting a different syntax error, saying that there is an “unexpected symbol near ‘?’”
The odd thing is that there is no ‘?’ in that code.
To make sure everyone is up to date, here’s my current code:
[code]
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0 )
local ball
local x = 1 --change to how many times you want your function to call.
–Function to create objects up top
local function ballSpawn()
there may be an invisible ascii character in your code, just copy my code exactly and paste it on a new text document. and test it. [import]uid: 46529 topic_id: 14452 reply_id: 53679[/import]
I made a new document and copied your code into it, but I’m still getting the syntax error where there is an unexpected symbol near the question mark. I also tried the ‘show invisibles’ thing on TextWrangler. All I saw was an inconspicuous symbol on line 4 (the line the error should have occurred on). [import]uid: 82408 topic_id: 14452 reply_id: 53707[/import]
I just found out something extremely important! I try copying literally any text off of Corona’s site and it gives me this exact same syntax error, saying that there was an unexpected symbol near ‘?’. I’ll try hand-typing some of the code you showed me and see if works. [import]uid: 82408 topic_id: 14452 reply_id: 53995[/import]
It works! I wrote the text in a different, un-corrupted file instead of straight-copying it off of the forum and it worked. Apparently copying the code off of Corona’s site brings along an unwanted bug that corrupts the file and makes it impossible to use for literally any code. Thanks for all your help, everybody! It works perfectly now, and I am extremely happy. Again, thank you! [import]uid: 82408 topic_id: 14452 reply_id: 53998[/import]
I am happy to hear you got it working finally. Can you tell me which browser you are using? it may related with your browser because I can copy an paste the code and it works. I use chrome. [import]uid: 46529 topic_id: 14452 reply_id: 54011[/import]