Page 1 of 1

Cant Move Images via Function

Posted: Fri Dec 20, 2019 5:31 pm
by meidera
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

Re: Cant Move Images via Function

Posted: Fri Dec 20, 2019 6:19 pm
by Klaus
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

Re: Cant Move Images via Function

Posted: Fri Dec 20, 2019 6:57 pm
by capellan
Image IDs are created with a number higher than 1000, so probably you want the image number.

Al

Re: Cant Move Images via Function

Posted: Fri Dec 20, 2019 7:08 pm
by Klaus
HA, good point, did not notice that one! :D

Re: Cant Move Images via Function

Posted: Fri Dec 20, 2019 7:52 pm
by dunbarx
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