Jump to content



0

Can we use two or more DEFs that use the same string?


6 replies to this topic

#1 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 20,923 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Tue Aug 30, 2011 4:33 AM

If I want to reuse bits in other places in my program (using different aliases), how do I do that using DEF? The following will not work:

   def Bit_Debounce_Fire=BitOp_All_Purpose_01{1}

   def Bit_Debounce_Joystick=BitOp_All_Purpose_01{1}


When I was using DIM only, I could reuse bits with different aliases all I wanted as long as I used the correct bit (for example, BitOp_Debounce_Joystick{1}).

Is there a way to use more than one alias with the same bit using DEF or is the only solution to use DIM?


Thanks.

#2 ScumSoft OFFLINE  

ScumSoft

    Moonsweeper

  • 331 posts
  • Location:Polysorbate 60

Posted Tue Aug 30, 2011 5:11 AM

[edit]Sorry for the unclear explanation, that is what I get for posting at 4am on my ipod.
def is nothing more than a double reference as a convenience to the dim statement, but is used differently.

You can say:
 dim Apple = a
 dim Banana = b
 def Pear=Apple
whenever you say Pear = 5, what gets said to the compiler is Apple = 5 (not pear), it's a convenience thing to reference the same variable by different names.

A work around for your problem without changing compiler version would be to reference the reference:
   def Bit_Debounce_Fire=BitOp_All_Purpose_01{1}

   def Bit_Debounce_Joystick=BitOp_All_Purpose_01{1}

   rem becomes
   def Bit_Debounce_Fire=BitOp_All_Purpose_01{1}

   def Bit_Debounce_Joystick=Bit_Debounce_Fire

That's what I meant in a VERY abstract sort of way.

Edited by ScumSoft, Tue Aug 30, 2011 7:43 PM.


#3 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 20,923 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Tue Aug 30, 2011 6:10 AM

View PostScumSoft, on Tue Aug 30, 2011 5:11 AM, said:

Def is the same as saying X points to Y, where as Dim says for every use of X treat it as Y.

So Dim Apple = a is saying when apple is used modify a instead.
and Def Banana=Apple{7} is saying when I say banana, what I really mean is Apple{7} so use that

Now when you declare a dim you can have multiple aliases for a single variable, but when you declare the use of define(def) your telling it to replace every usage of X with Y and if you also want it to replace Z with Y it wont work since its been assigned to replace X instead.

So to fix your issue assign x=Banana{7} and y=x
I'm not sure I understand your last line.

I've been doing stuff like this for a while without DEF:

   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '
   rem  '  All-purpose bits for various jobs.
   rem  '
   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '
   dim BitOp_All_Purpose_01 = t
   dim BitOp0_Debounce_Reset = t
   dim BitOp0_Fingernail_Soup = t
   dim BitOp4_Toggle_Screen = t
   dim BitOp5_B_Direction_X = t
   dim BitOp6_B_Direction_Y = t
   dim BitOp7_Missile0_Moving = t




   Examples:

   if BitOp0_Debounce_Reset{0} then blah blah blah

   if BitOp0_Fingernail_Soup{0} then blah blah blah

   if BitOp4_Toggle_Screen{4} then blah blah blah

   if BitOp7_Missile0_Moving{7} then blah blah blah

So, unless the last line in your post means something else, if you want to have more than one meaningful alias in other places in a program, you need to use DIM. DEF is only useful for replacing one logical name with one unique string. Multiple uses of the same string is not allowed.

Edited by Random Terrain, Tue Aug 30, 2011 6:12 AM.


#4 RevEng OFFLINE  

RevEng

    River Patroller

  • 2,010 posts
  • bit shoveler
  • Location:Canada

Posted Tue Aug 30, 2011 7:43 AM

View PostRandom Terrain, on Tue Aug 30, 2011 4:33 AM, said:

If I want to reuse bits in other places in my program (using different aliases), how do I do that using DEF? The following will not work...

It works for me, so you must be running into some other issue. I put together the following minimal program, and it compiled fine, and produced the expected assembly code...

 dim BitOp_All_Purpose_01=a
 def Bit_Debounce_Fire=BitOp_All_Purpose_01{1}
 def Bit_Debounce_Joystick=BitOp_All_Purpose_01{1}

 if Bit_Debounce_Fire then goto done
 if Bit_Debounce_Joystick then goto done
done


#5 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 20,923 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Tue Aug 30, 2011 8:05 AM

View PostRevEng, on Tue Aug 30, 2011 7:43 AM, said:

It works for me, so you must be running into some other issue. I put together the following minimal program, and it compiled fine, and produced the expected assembly code...

 dim BitOp_All_Purpose_01=a
 def Bit_Debounce_Fire=BitOp_All_Purpose_01{1}
 def Bit_Debounce_Joystick=BitOp_All_Purpose_01{1}

 if Bit_Debounce_Fire then goto done
 if Bit_Debounce_Joystick then goto done
done
Thanks. I just tried that with and without bank-switching and it compiled for me too.

I tried it with the Titlescreen Kernel and it compiled.

I added your score background color code and it compiled.

The only thing I can think of is that there might be some naughty if-then that is a little too long.

#6 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 20,923 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Tue Aug 30, 2011 9:57 AM

Looks like it's causing the same problem as here:

http://www.atariage....68#entry2145268


It's that old AND #65536 error popping up with Bit_Ship_Up.

I've ripped out chunks of the program, trying to find what was causing the problem. I'd rip out a chunk, save, compile, rip out a chunk, save, compile . . . I ended up ripping out everything except the DIMs and DEFs, then it would finally compile.

You'd think I would have found the cause of the problem by ripping out code piece by piece like that.

I'll leave the current DEFs the way they are since they seem to be working, but I'll go back to the old way of using bits for anything new that I need to add.

Edited by Random Terrain, Tue Aug 30, 2011 9:58 AM.


#7 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 20,923 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Tue Aug 30, 2011 10:00 PM

View PostRandom Terrain, on Tue Aug 30, 2011 9:57 AM, said:

I'll leave the current DEFs the way they are since they seem to be working, but I'll go back to the old way of using bits for anything new that I need to add.
I changed my mind. I converted all DEFs to DIMs:

www.atariage.com/forums/blog/120/entry-8495-seaweed-assault-defs-to-dims/




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users