Change Image

Here is my code:

local imgtable = { "1.png", "2.png","3.png","4.png","5.png" }; local r =math.random(1,#imgtable) local img = display.newImageRect(imgtable[r],40,40) img.x=display.contentCenterX img.y=display.contentCenterY local button = display.newCircle(img.x,img.y+80,40) local function changeImage() --????? end button:addEventListener("tap",changeImage)

I have a table of images and a random image from the table is displayed in the center. However I have button where the image is changed to a random image in the table. However, I do not know how to do this.

What do I do?

See: https://docs.coronalabs.com/tutorial/media/swapImages/index.html

Gary,

While Rob has already answered your question, I’m a little curious.  This seems like a pretty straight forward problem to resolve or look up, but clearly you had trouble solving it.

That is OK. I’m not poking fun or trying to give you a bad time.

However, I’m curious about what steps you took to try to solve this.  Can you list them below?

Specifically, 

  • What pages did you look at here on the site?
  • What about external searches did you make?
  • Did you look at any examples that come with Corona?

Again, I’m not asking these questions to poke you.  I really want to know.  Then, I may be able to give you some feedback that will make solving problems easier for you in the future (and maybe others too.)

Please try to be clear, precise, and concise in your answer (if you respond).  A single paragraph will be of no use.  I’m looking for full sentences, line breaks where appropriate, bullet lists, basically an answer following the form of this post.

Thanks,

Ed

@Rob thanks, it confused me a little at first but now I got it

@roaminggamer I searched up “change image corona” and I didnt find anything but forum posts back in like 2015, so I guessed it wasnt updated.

I do not have corona simulator with me right now so I cant test out the code.

I am not sure why you would like me to write to a one page answer (i am guessing one page or maybe 3 paragraphs) on why I asked this question.

In my opinion, what you asked for is pretty weird and I am pretty sure no one in their right mindset would write such a response for you…

I hoped that answered your question

Gary,

Hmmm… No need to get testy.  I was sincere when I said I wanted to help.  Perhaps I wasn’t clear.

I see a lot of folks ask questions and I try to help them.  I’m sure I’ve helped you a few times by now.

I often wonder, “Why didn’t XYZ person find that answer?  What prevented them from locating it?”

At 83 posts, you seem to be new to Corona and I’ve seen that your posts are pretty good.  

I thought to myself.  “I’ve helped this guy and he seems pretty serious.  However he asks questions that I think should be answerable from the content on the site.  What is going wrong?”

So I posed my questions (above) and hoped for some insights that I could turn around into solutions for you and others.

Finally, you didn’t give me a lot to work with, but I have some ideas that may help you get better answers in the future…

Suggestions

  1. You didn’t mention using or searching the API page:  https://docs.coronalabs.com/api/
  • I usually go here, then…
  • Using my browser I search for words that make sense.  In this case words that would have gotten you started:
    • fill
    • bitmap
    • paint
  • This gets more useful and easier the more  you learn about Corona
  1. When ‘searching’, don’t use the built-in search (which I assume you did).  Instead I always use Google with a search like this: 
  • keyword keyword site:coronalabs.com

This would have helped find the answer you needed this time:   fill image site:coronalabs.com

Tip: Don’t go crazy on keywords (1 … 3 is best) or you’ll get too diluted an answer.

  1.  Less applicable in this case, you might also try searching github.com.  There is a LOT of content there related to Corona.

  2. Also, never forget, I have lots of free code and answers here:  https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd

Oh, I’m not being testy. I was just confused and baffled on why you asked for a detailed answer on why I didn’t find the answer in the documentation.

As for your question:

Why didn’t XYZ person find that answer?

I guess that the most simplest answer is that the person didn’t bother to search or didnt search up the right terms.

Honestly I just use the forum for just asking question(as do many people too).

Its more faster than looking allover the documentations and getting better answers from experts of corona.

I guess that the most simplest answer is that the person didn’t bother to search or didn’t search up the right terms.

Honestly I just use the forum for just asking question(as do many people too).

Its more faster than looking all over the documentations and I get getting better answers from experts of corona. 

Well that it disappointing, but very good to know (will save me a lot of time). 

Gary, I see where RG is coming from, although maybe I wouldn’t have asked for an essay :slight_smile:

It does get annoying when people post questions that an answer is already easily available for. I’d like to think posting on the forums is a last resort when all other avenues have been exhausted. Laziness or speed is not an excuse - perhaps the likes of roaminggamer, Sphere Game Studios, horacebury should be lazy too and not come on here at all, and increase the speed of their own projects? Sounds like that’s where RG might be heading.

As you say it’s good to get advice from experts, but I suspect they didn’t become experts by asking a question every time they hit a small roadblock, only at key moments when they were truly stuck. It does begin to wear the community out and when you really do hit a problem that can’t be solved on your own, there might be no one left to help.

_ Last response I think… _

I don’t know why my request has been considered to be an essay.  I prefer the opposite as per my request:

Please try to be clear, precise, and concise in your answer (if you respond).

The remainder of that line:

 A single paragraph will be of no use.  I’m looking for full sentences, line breaks where appropriate, bullet lists, basically an answer following the form of this post.

I meant that  I didn’t want a single rambling paragraph with no line breaks, unchecked grammar, and run-on sentences.  i.e. I was only asking that it be made legible.

I see a HUGE number of illegible posts in our forums and I can’t figure out why this is.  My best guess is that folks are posting from mobile devices which make no sense to me.  However, I’m old school and a crotchety old git.   :slight_smile:

Unfortunately, when one asks for corrections like that in advance I think it automatically triggers an angry (or at best puzzled) response as in this case.  Well,  I can’t be accused of not trying.

That would be a nightmare. 

See: https://docs.coronalabs.com/tutorial/media/swapImages/index.html

Gary,

While Rob has already answered your question, I’m a little curious.  This seems like a pretty straight forward problem to resolve or look up, but clearly you had trouble solving it.

That is OK. I’m not poking fun or trying to give you a bad time.

However, I’m curious about what steps you took to try to solve this.  Can you list them below?

Specifically, 

  • What pages did you look at here on the site?
  • What about external searches did you make?
  • Did you look at any examples that come with Corona?

Again, I’m not asking these questions to poke you.  I really want to know.  Then, I may be able to give you some feedback that will make solving problems easier for you in the future (and maybe others too.)

Please try to be clear, precise, and concise in your answer (if you respond).  A single paragraph will be of no use.  I’m looking for full sentences, line breaks where appropriate, bullet lists, basically an answer following the form of this post.

Thanks,

Ed

@Rob thanks, it confused me a little at first but now I got it

@roaminggamer I searched up “change image corona” and I didnt find anything but forum posts back in like 2015, so I guessed it wasnt updated.

I do not have corona simulator with me right now so I cant test out the code.

I am not sure why you would like me to write to a one page answer (i am guessing one page or maybe 3 paragraphs) on why I asked this question.

In my opinion, what you asked for is pretty weird and I am pretty sure no one in their right mindset would write such a response for you…

I hoped that answered your question

Gary,

Hmmm… No need to get testy.  I was sincere when I said I wanted to help.  Perhaps I wasn’t clear.

I see a lot of folks ask questions and I try to help them.  I’m sure I’ve helped you a few times by now.

I often wonder, “Why didn’t XYZ person find that answer?  What prevented them from locating it?”

At 83 posts, you seem to be new to Corona and I’ve seen that your posts are pretty good.  

I thought to myself.  “I’ve helped this guy and he seems pretty serious.  However he asks questions that I think should be answerable from the content on the site.  What is going wrong?”

So I posed my questions (above) and hoped for some insights that I could turn around into solutions for you and others.

Finally, you didn’t give me a lot to work with, but I have some ideas that may help you get better answers in the future…

Suggestions

  1. You didn’t mention using or searching the API page:  https://docs.coronalabs.com/api/
  • I usually go here, then…
  • Using my browser I search for words that make sense.  In this case words that would have gotten you started:
    • fill
    • bitmap
    • paint
  • This gets more useful and easier the more  you learn about Corona
  1. When ‘searching’, don’t use the built-in search (which I assume you did).  Instead I always use Google with a search like this: 
  • keyword keyword site:coronalabs.com

This would have helped find the answer you needed this time:   fill image site:coronalabs.com

Tip: Don’t go crazy on keywords (1 … 3 is best) or you’ll get too diluted an answer.

  1.  Less applicable in this case, you might also try searching github.com.  There is a LOT of content there related to Corona.

  2. Also, never forget, I have lots of free code and answers here:  https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd

Oh, I’m not being testy. I was just confused and baffled on why you asked for a detailed answer on why I didn’t find the answer in the documentation.

As for your question:

Why didn’t XYZ person find that answer?

I guess that the most simplest answer is that the person didn’t bother to search or didnt search up the right terms.

Honestly I just use the forum for just asking question(as do many people too).

Its more faster than looking allover the documentations and getting better answers from experts of corona.

I guess that the most simplest answer is that the person didn’t bother to search or didn’t search up the right terms.

Honestly I just use the forum for just asking question(as do many people too).

Its more faster than looking all over the documentations and I get getting better answers from experts of corona. 

Well that it disappointing, but very good to know (will save me a lot of time). 

Gary, I see where RG is coming from, although maybe I wouldn’t have asked for an essay :slight_smile:

It does get annoying when people post questions that an answer is already easily available for. I’d like to think posting on the forums is a last resort when all other avenues have been exhausted. Laziness or speed is not an excuse - perhaps the likes of roaminggamer, Sphere Game Studios, horacebury should be lazy too and not come on here at all, and increase the speed of their own projects? Sounds like that’s where RG might be heading.

As you say it’s good to get advice from experts, but I suspect they didn’t become experts by asking a question every time they hit a small roadblock, only at key moments when they were truly stuck. It does begin to wear the community out and when you really do hit a problem that can’t be solved on your own, there might be no one left to help.

_ Last response I think… _

I don’t know why my request has been considered to be an essay.  I prefer the opposite as per my request:

Please try to be clear, precise, and concise in your answer (if you respond).

The remainder of that line:

 A single paragraph will be of no use.  I’m looking for full sentences, line breaks where appropriate, bullet lists, basically an answer following the form of this post.

I meant that  I didn’t want a single rambling paragraph with no line breaks, unchecked grammar, and run-on sentences.  i.e. I was only asking that it be made legible.

I see a HUGE number of illegible posts in our forums and I can’t figure out why this is.  My best guess is that folks are posting from mobile devices which make no sense to me.  However, I’m old school and a crotchety old git.   :slight_smile:

Unfortunately, when one asks for corrections like that in advance I think it automatically triggers an angry (or at best puzzled) response as in this case.  Well,  I can’t be accused of not trying.

That would be a nightmare.