How do you call a function from another script and call certain functions from a variable that is random

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dava
:warning: Old Version Published before Godot 3 was released.

I am trying to make something like an AI for an enemy, when the game starts, the enemy walks in a random direction, and when it collides with an area, it changes direction or keeps going forward, but none of that works here is my project structure:

Node2D
-enemy
-areas_ai
–area00
–area01

# Enemy script
extends KinematicBdoy2D

  var direction = Vector2(0, 0)
  onready var anim = get_node("anim")
  const enemy_speed = 0.1
  const speed = 200

 func _ready():
    set_fixed_process(true)
    pass

 func _fixed_process():
         var num = randomize()
         if(num == 1):
            move_up()
        elif(num == 2):
            move_down()

     move(direction*speed*delta)
     if (is_colliding()):
	  print("Collision with ",get_collider())
	  var n = get_collision_normal()
	  direction = n.slide( direction )
	  move(direction * speed * delta) 
	  pass
pass

 func move_up():
    direction += Vector2(0, -enemy_speed)
    if(not anim.is_playing() or anim.get_current_animation().basename() !='walk_back'):
	    anim.play("walk_back")
            pass
  pass

here is the Node2D script

#Node script
 extends Node2D

 var num                  = range(1, 2)
 onready var enemy        = get_node("enemy")
 onready var area00       = get_node("areas_ai/area_ai")
 onready var area01        = get_node("areas_ai/area_ai01")

 func _ready():
    area00.connect("body_enter", self, "_area_zero")
        area01.connect("body_enter", self, "_area_one")

 func _area_zero(body):
   enemy.move_down()
   pass

 func _area_one(body):
       if(num == 1):
          enemy.move_up()
       if(num == 2):
           enemy.move_down()

I also want the random number to keep randomizing between 1 and 2 and even 1, 2, and 3, and when like maybe the number is 1 the enemy would move up, when the number is 2, the number would move down, or when the number is three, it would move left, or something like that, but i have no idea on how

:bust_in_silhouette: Reply From: jandrewlong

While you do want to call randomize() once, you don’t need to call it in fixed_process.

Also, randomize() doesn’t return anything, so var num = randomize() doesn’t work, you’ll probably want var num = randi() % 2 instead (in your enemy script’s fixed_process), then compare num to 0 and 1, not 1 and 2