Taking an object from a function that has not been declared? [closed] - lua

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Taking an object from a function that has not been declared?
Well, basically that's it, I need to use
character:removeEventListener ("touch", movePerson)
only that movePerson only happen after ... And I can not leave it for later, must be before ... would somehow ?
Asked more details, but that is almost all the information '-' It's simple: I have to draw that line up inside a function that is before movePerson function ... I think it's more confusing huh? :S

You can define it on top, and assign the function to it later, like so:
local character = display.newRect(200,200,200,200)
local movePerson -- This will be a reference to the function, so functions below can "see" it.
local function addListener()
character:addEventListener ("touch", movePerson)
end
local function removeListener()
character:removeEventListener ("touch", movePerson)
end
movePerson = function(event) -- Right here you declare it to the variable on top
print(tostring(event.phase))
end
addListener()
removeListener()
Note that you must remove it after it has been declared, like in the example, and i don't think it is a good practice to do this, unless it is absolutely necessary.

Related

Add if in Ruby heredocs [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am trying to display product details using javascript. I am using haml and RoR-4.2.1. I have the following code
var a = new Array();
#{#productlist.map do |prdct|
<<-EOS
var t = new Object();
t.product_id = '#{prdct.product_id}';
t.name = '#{prdct.name}';
t.address = '#{prdct.address}';
a.push(t)
EOS
end.join("\n")}
I have a model images which contains the images for the products. A product may or may not have images. So to display images I have added the following
t.shop_image =
"#{if prdct.images.present?
prdct.images.first.image_url
else
''
}"
statements before push statement. But it is generating an issue. How can I add if checking in the heredocs.
Approach 1: do the same thing you'd do with "normal" strings.
"#{product.images.present? ? product.images.first.image_url : ''}"
Approach 1+: extract the expression above into a variable, so that your template contains less logic.
Approach 2: don't abuse heredocs and use ERB instead.

Lua scripting errors [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
[ERROR] Lua is unable to understand file "darkrp_customthings/jobs.lua" because its author made a mistake around line number 21.
The best help I can give you is this:
There is an opening '(' bracket at line 20, but this bracket is never closed or not closed in time. It was expected to be closed before the '=' at line 21.
Can someone help correct the errors in my code?
The code:
https://www.dropbox.com/s/o2w9jx2kqefu2n0/job%20.txt?dl=0
You wrote something like this (simplified):
TEAM_TERRORIST = AddExtraTeam(
"Terrorist",
customCheck = function(ply) end
)
This is not valid syntax in Lua, where there are no named parameters.
Maybe the AddExtraTeam function expects a table instead? E.g. this is valid syntax:
TEAM_TERRORIST = AddExtraTeam{
"Terrorist",
customCheck = function(ply) end
}
Not sure this is the right solution though, I don't know DarkRP.

Recognize Specific Characters In a Text [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
hy
im making an app to help students study better but im having trouble. the app let you make notes between other things,but I need a code that can recognize specific characters in a text for example the user writes in a note "Dolphins : are cetacean mammals closely..." i need the app to recognize the character : and also the part thats on the left it needs to be save to use later, as a variable and the part of the right also but as a different variable so I can use them later.
if you can get me the code for that it be great but if possible i preferred a tutorial :)
(the app is for iPhone im using Xcode 5)
Something like:
NSArray *stringArray = [yourNSString componentsSeparatedByString:#":"];
NSString *leftString = stringArray[0];
NSString *rightString = stringArray[1];
EDIT: Just make sure string has the ":" character.

Use object with variable name in Delphi [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm new in delphi and i thought it might be safer to swap object names in loop instead of copying whole block for each object. So I need to use variable name as some objects name.
Here is an example of what i tried and what i am trying to do.
Var
YazGrid: TStringGrid;
I defined a variable for grid name as above and i am trying to use like this:
Some Loop
begin
if a_variable>=10 then
YazGrid:=form1.StringGrid1
else
YazGrid:=form1.StringGrid2;
YazGrid.Cells[1,i] := 'SomeText';
End;
As the result- it comes out with the "Access Violation" error. How should i do this?
Thanks in advance.
Everything looks right in your code.
Make sure that variable "i" in bound. Anyway, even if "i" out-of-bound, this shound't raise Access Violation.
Tested with Delphi XE2 and XE4.
I suppose that error occure in code that not showed in your sample.

Ruby how to extract element value from a data structure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
x = {"utf8"=>"✓",
"authenticity_token"=>"xxxxxxxxxxxxx=",
"file"=>#>,
"unit_id"=>"00001"}
I have ruby data structure like this and um trying to get the value of #original_filename field
I tried something like this
x["#original_filename"]
and
x[:original_filename]
But both has thrown me an error . How to access that specified element value?
looks like you're trying to upload a file; from your tiny screenshot maybe you're referring to params[:file].original_filename?
The parameter ["file"] is a ActionDispatch::Http::UploadedFile, which has the original_filename member variable, as you can see in the params displayed in your image or here:
http://api.rubyonrails.org/classes/ActionDispatch/Http/UploadedFile.html
So, the way to get this value would be x["file"].original_filename

Resources