Best way to add script dynamically

I am using a javascript/jquery plugin called Royalslider.

The slider is initalized with a script (example below). Essentially, I need two versions of it. One if the post has a “gallery” (made in Advanced Custom Fields), and the other if it just has a standard featured image. I don’t need or want a script if it doesn’t have either.

I am leaning towards adding to my functions.php if statements with wp_enqueue_script to add the script.

The other option would be to echo the script out in my template file.

I’m just stuck with which would be the best way to do this.

jQuery(document).ready(function($) {
    fullscreen: {
      enabled: true,
      nativeFS: true
    controlNavigation: 'thumbnails',
    autoScaleSlider: true, 
    autoScaleSliderWidth: 960,     
    autoScaleSliderHeight: 640,
    loop: true,
    imageScaleMode: 'fit-if-smaller',
    navigateByClick: true,
    arrowsNavAutoHide: true,
    arrowsNavHideOnTouch: true,
    keyboardNavEnabled: true,
    fadeinLoadedSlide: true,
    globalCaption: false,
    globalCaptionInside: false,
    thumbs: {
      appendSpan: true,
      firstMargin: true,
      paddingBottom: 4