Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Getting runtime error when adding setFillcolor attribute to an array
Started by IndieEnthusiast Feb 11 2019 12:02 PM

- - - - -
19 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 217 posts
  • Corona SDK

ERROR: Runtime error
                    levelselection.lua:24: attempt to index field '?' (a nil value)
                    stack traceback:
                    levelselection.lua:24: in function '?'
                    ?: in function 'dispatchEvent'
                    ?: in function 'gotoScene'
                    mainmenu.lua:114: in function '?'
                    ?: in function <?:190>
 
Getting this error when I try to add display attribute to an array like setcolor, code :
 

myRoundedRect = display.newRoundedRect( 1, 1, 1, 1, 1 )

  for i = 1, 4, 1 do
    for j = 1, 5, 1 do

      myRoundedRect[i] = display.newRoundedRect( 225*i, 100*j, 80, 50, 12 )
      myRoundedRect[i]:setFillColor(1,2,1)
    end
  end

Basically this is helping me draw a level selection menu, but when I try to add display image attribute myRoundedRect[i]:setFillColor(1,2,1), the error above is  being thrown.

 

With a simple for loop was able to create this, I am focusing on minimizing code and do not want to repeat writing code for each display object, any idea?

 



[TOPIC: post.html]
#2

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 217 posts
  • Corona SDK

I would like to then later on depending on which myroundrect[i][j] is clicked, will transition to the correct level. I hope you get the picture?



[TOPIC: post.html]
#3

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 757 posts
  • Corona SDK

line 24 in your code refers to a nil value but you are not showing your code with line numbers...


  • IndieEnthusiast likes this

[TOPIC: post.html]
#4

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 217 posts
  • Corona SDK

Here is the screenshot

Attached Thumbnails

  • code.jpg


[TOPIC: post.html]
#5

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 217 posts
  • Corona SDK

When I use myRoundRect[i].setFilColor , then I get this error



[TOPIC: post.html]
#6

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,723 posts
  • Corona SDK

Many things going on here. You should set up a proper table called myRoundedRect, instead you seem to be just creating a 1x1 rect and then adding all your rects to that. Yes, technically it's a table, but this isn't the right way to do it, and It's possible your bug is related to this. 

 

Put "local myRoundedRect = {}" at the top of your lua file. 

 

Secondly, every time you loop through j, you are overwriting the previous myRoundedRect[I] with a new one, and losing forever the reference to the previous one.

 

A colour of (1,2,1) is the same as (1,1,1). The maximum value is 1.

 

Lastly I don't think roundedRect is really suitable for actual use, it creates a very pixelated image. I would import my own rounded rectangle and use display.newImageRect.



[TOPIC: post.html]
#7

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 757 posts
  • Corona SDK

first you create myRoundedRect as a display object

then you try to loop through myRoundedRect as a table

that wont work

remove line 18 (or rename it something else)

under it type "myRoundedRect={}" to set it as a table

then the loop should work



[TOPIC: post.html]
#8

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 757 posts
  • Corona SDK

what nick said  ;)



[TOPIC: post.html]
#9

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 757 posts
  • Corona SDK

@indieEnthusiast

 

I notice that you are often enough posting problems and issues that you would not come across if you would have basic knowledge of lua and corona. Please note, I am not saying you dont know how to code in general, but lua and corona seems to be new for you.

 

It is clear that you have a desire to quickly make one or more apps, but if I may come with a piece of advice, the time you spend struggling with these issues could be better spent studying the corona documentation. it is very well written and if you give it one week, you will find that you quickly get the basics down right, and you're progress will speed up drastically. Maybe not as exciting but definitely worth it in the long run.


  • IndieEnthusiast likes this

[TOPIC: post.html]
#10

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 217 posts
  • Corona SDK

Hi anaqim,

 

You are absolutely right. The issue is I often do not get a lot of time to code. I work fulltime and by the time I am at home I mainly get 1 or 2 hours at night to code. I know if I spend more time I will get better at it. I guess I should be more patient. Thanks for your advice. When I get stuck, I think of so many experts in this forum who have helped me out previously. However there is no shortcut to learning. I will google and try to figure out myself first before asking here.


  • anaqim likes this

[TOPIC: post.html]
#11

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 757 posts
  • Corona SDK

Hi indieEnthusiast,

 

Thanks for not getting offended by my post.

I know posts like that can so easily get taken the wrong way.

 

There simply never is enough time, period  ^_^

Started myself some 2 years ago now and went through the same thing.

Corona docs was (and still is) my go to bible whenever I have a question or need to look something up.

 

I would advice against using google as the primary source for info as much is outdated. Corona Docs is straight to the point, always updated with examples and instantly available. What more do you need :) 

 

Have a great day!



[TOPIC: post.html]
#12

carloscosta

[GLOBAL: userInfoPane.html]
carloscosta
  • Contributor

  • 626 posts
  • Corona SDK

my advice is stop wasting 1 or 2 hours coding. spend them on reading corona api, corona book, or lua book or even online video tutorials.

after 2/4 weeks try to code without help.

 

Why people invert the process and start programming without having a clue with the basic stuff, beats me.

 

The time you spend to correct a lvl 0 error like this, you would have learned 100x more stuff reading a proper book.

 

My 2 cents.



[TOPIC: post.html]
#13

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 757 posts
  • Corona SDK

yeah but then there is this burning flame of creativity and enthusiasm that need feeding, and while logic dictate its better to study first, study doesnt feed that flame  :P


  • IndieEnthusiast likes this

[TOPIC: post.html]
#14

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 217 posts
  • Corona SDK

:unsure:  :unsure: Also the fact that back of the mind I know the big Corona Bosses resides in this forum...which can make one a little bit lazy 



[TOPIC: post.html]
#15

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 757 posts
  • Corona SDK

That is actually not quite true.

Almost all the people who answer here are users of various skill levels, and not employees.

This is likely why posts that dont make any sense or clearly are missing a lot of info, just go unanswered.


  • IndieEnthusiast likes this

[TOPIC: post.html]
#16

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 217 posts
  • Corona SDK

I think I will try to battle it out first myself the lua + corona codes. To be frank I am not very good with looping mechanism of while/for, it was the first time I used for loop, so the fact is I should have gone through more example codes and be more patient. Asking will not always improve learning. Constructive criticism is always good.



[TOPIC: post.html]
#17

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 217 posts
  • Corona SDK

Everything is now working as expected, last night took a little bit of time understanding lua arrays and the examples given. So now the level selection template is almost complete. I just need to give images to the placeholders and implement composer.gotoScene.



[TOPIC: post.html]
#18

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 757 posts
  • Corona SDK

:D



[TOPIC: post.html]
#19

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 217 posts
  • Corona SDK

I want to just finish this thread by saying that please do not discourage others from questioning. Something which is "very basic" to you may not be very basic to someone else. If you do not have time to respond or time to point to the correct documentation, its acceptable. However it is also not acceptable to flood the forum with very basic queries. We need to come to terms with the fact that not everyone is in the same level of corona knowledge. Something appearing to be "very basic" to someone, may not be very basic to others even after following a well documented piece of code. So encourage others to question and have a lively forum, if you do not have time to respond, then dont. I may take it quite positively, but others may not. I am just putting a perspective out there. I have learned a lot from this forum and I hope to continue to do so. 

 

I am not going after any specific individuals here but just letting you know my opinion. I have followed a number of forum threads and I am seeing similar comments, "its very basic", which is kind of discouraging to the person who is spending his time exploring and writing for a solution end of the day.



[TOPIC: post.html]
#20

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 757 posts
  • Corona SDK

Hi indie,

 

Your point is valid and I believe everyone really do try to behave accordingly, but ... and there is always a but, isnt there...

 

We see quite a few users posting on the forum for the first time, expecting others to solve their issues, asking questions like:

 

"I want my box to drop faster and move other box, how to do that"

"i want to make flappy bird app, can someone show me code"

"i want to center a ball but it is not centerd on screen, why? give me full code please"

 

and my favourite...

 

"here are my 2000 code lines, the bird doesnt flap. where is problem, help"

 

Then there is formatting. When asking for help it is imperative the post includes enough info so that someone who doesnt know the app can read it and understand the intentions. In most cases that means providing all code snippets involved in the problem. We see quite a few partial code postings, making it something between mission impossible and playing cluedo to try and find out whats going on.

 

One has to learn how to crawl before one can start walking, and one needs to walk steady before one can try running. Yet, I have the impression that many are just looking for a quick fix so they can get up and running from day one, which is impossible. 

 

To learn coding one must first understand how code logic and setup function (pun intended). It's a little like, you wont be able to read russian before you have learned the russian alphabet.  Any and all attempts are doomed to fail. Time spent studying is time well spent. Nothing will bring you faster up to speed than... good old fashioned studying.

 

People who read these forums are mostly users of different skill levels, and having to read incomplete, not to mention demanding and sometimes impolite posts, feels like a waste of everyones time. The result is people will unsubscribe and forum will slowly die as nobody read it anymore.

 

The main purpose of the forum is to have a place to ask other users for help when one is stuck with a problem after having tried to solve it troubleshooting own code step by step, reading the documentation, running and checking demo samples, and searching on google.

 

I often end up referring to the documentation when i know the question is explained there. Although I sometimes link to the related page directly, my purpose is to give a hint as where to find answers and learn corona, step by step.

 

I may sound like a broken record but I stand by it by my own experience.

 

Corona docs is all you need to get going  :)




[topic_controls]
[/topic_controls]