Skip to content
View in the app

A better way to browse. Learn more.

MagicDuel Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

MDScript Object Oriented Programming

Featured Replies

Sadly the closest you can get to it is arrays, as far as I know. You can't even define your own functions.

 

Edit: You can define your own functions.

Edited by samon

  • 1 year later...

I tried playing around with MDScript a little more and apparently you can use functions. That being said I haven't found a way to use variables from outside a function (other than passing them as parameters and returning them) inside the function. In that sense it is more like functional programming than OOP. Also it doesn't appear to be possible to use MDScript specific methods inside a user defined function.
 
e.g: 

function bar()
{
    echo @vv; //Always echoes nothing
    @vv = 'bar';
}
 
@vv = 'foo';
bar();
echo @vv; //echoes foo
 
function baz(@vv)
{
    @vv = 'baz';
    return @vv;
}
baz(@vv);
echo @vv; //still foo
 
@vx = baz(@vv);
echo @vv; //still foo
echo @vx; //vx is now baz
 
function err()
{
    echo uv('id');
}

err(); //Gives an error because uv is undefined

Edited by samon

  • Root Admin

That being said I haven't found a way to use variables from outside a function (other than passing them as parameters and returning them) inside the function.


Tried using global keyword?

Also it doesn't appear to be possible to use MDScript specific methods inside a user defined function.


Tried passing them in?

Global is a restricted keyword (thrice even) so that doesn't work.

As for passing in the methods, you can pass in the return values, but other than that not sure how it would work. (It is, for fairly obvious reasons, not possible to call a method stored in a variable, if that is what you mean.)

  • Root Admin

Global is a restricted keyword (thrice even) so that doesn't work.


I shall add that to my list to review. we can probably expose the functions by default or via namespacing.

As for passing in the methods, you can pass in the return values, but other than that not sure how it would work. (It is, for fairly obvious reasons, not possible to call a method stored in a variable, if that is what you mean.)


Not possible in MDscript, or PHP? http://php.net/manual/en/functions.variable-functions.php

You can use MDScript specific functions from within your own functions, but you have to add:

(prepare function)

on the first line inside the body of the function.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Forum Statistics

  • Total Topics 17.5k
  • Total Posts 182.2k

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.