Cant Move Images via Function

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
meidera
Posts: 1
Joined: Fri Dec 20, 2019 5:21 pm

Cant Move Images via Function

Post by meidera » Fri Dec 20, 2019 5:31 pm

Hello everyone, kinda new here!
Really got everything solved so far from just reading through posts or guides but this really throws me off.
I am working on a little game with playermodels moving across a board so i made the function "movePlayer".
myVar gets the number of the field it has to move to, using IDs for that because didnt figure out how to otherwise and playervar
is the name of the image which is a string. It also has to check if player moves above the Goal Field which has the id 41.
Whenever i run this i tells me that the object does not exist. Am i missing something?

Code: Select all

on movePlayer myVar,playervar
   if myVar < 41 then
      move image playervar to the location of image id myVar
   else if myVar > 41 then
      move image playervar to the location of image id 41
   end if
end movePlayer

Klaus
Posts: 11949
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Cant Move Images via Function

Post by Klaus » Fri Dec 20, 2019 6:19 pm

Hi meidera,

welcome to the forum!
Whenever i run this i tells me that the object does not exist.
What does not exist? "image playervar", "image id myVar" or "image id 41"?
Please show us that script, too.

Please check how you call that handler, I mean make sure that images with
that ID really exist.

Best

Klaus

capellan
Posts: 631
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

Re: Cant Move Images via Function

Post by capellan » Fri Dec 20, 2019 6:57 pm

Image IDs are created with a number higher than 1000, so probably you want the image number.

Al

Klaus
Posts: 11949
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Cant Move Images via Function

Post by Klaus » Fri Dec 20, 2019 7:08 pm

HA, good point, did not notice that one! :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6918
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Cant Move Images via Function

Post by dunbarx » Fri Dec 20, 2019 7:52 pm

Hi.

Technically, there is nothing wrong with using ID's or numbers to reference controls on a card.

I wouldn't. These are hard to read and to remember which is which, and numbers can change easily.

Name your controls, that way lies sanity.

There are occasions when a number within a name makes sense, and that is typically when a bunch of similar controls are to be referenced as a "group". Say you want to modify only certain fields that share a particular property. In such a case, I always name those fields with something like:

"myField 1", "myField 2", "myField 3", etc. Then you might:

Code: Select all

on mouseUp
   repeat with y = 1 to the number of flds
      if the short name of fld y = "myField" and the last word of the short name of fld y is an integer then
         set the height of fld y to "24"
      end if
   end repeat
end mouseUp 
You could also use those numbers to layer those fields, for example, or to set their locs in a topLeft mates to bottomRight order, or whatever.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”