Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: self defined global function  (Read 4654 times)

0 Members and 1 Guest are viewing this topic.

Drax

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 78
  • This engine rocks!
    • View Profile
    • Ganja Joe - And the myth of the holy pot
self defined global function
« on: April 03, 2004, 03:15:44 PM »

hi guys.

Im back again in programming an developing my game. but more about that later.

I need to know how I can define global functions or something like that. I want to make my dialoges in a seperated file, and get the dialoge in the other scripts with the simple line:

Dialoge1();

Is it possible? How? Im trying, but I've found no solution.

Thanx DraX

Logged
I'm Lost!

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re:self defined global function
« Reply #1 on: April 03, 2004, 03:28:07 PM »

Hi DraX !

Dialoge1();
Is it possible? How? Im trying, but I've found no solution.

If you saved your skript with the dialog functions, you can simply include it in your scripts.
for example: #include "scripts\mydialogs.inc"

(There are also global "functions" possible, but I suppose that's not really what you want.
You could e.g. define them as "methods" of the Game object. Or you create your own custom "Dialog" Object and assign the methods to them... you see there are a lot of ways actually ! :) )

 
Logged
Mooh!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:self defined global function
« Reply #2 on: April 03, 2004, 03:37:50 PM »

I'm voting for the custom object way.

Create a script file (dialogs.script) containing your funclions declared as methods.

Code: [Select]
method Dialogue1()
{
  ...
}

...


Then create a global object:

Code: [Select]
global Dlg = new Object("dialogs.script");

Then you can call anywhere:

Code: [Select]
Dlg.Dialogue1();

Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Drax

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 78
  • This engine rocks!
    • View Profile
    • Ganja Joe - And the myth of the holy pot
Re:self defined global function
« Reply #3 on: April 03, 2004, 08:19:03 PM »

Jeah! Thanx, it works fine now.

Now i've finished the gameplay of my planned demo version. It's one bigger quest and the start of the story. (lika a tutorial to learn the gameplay). Now just some interface and sound works to do.

I hope we can release next month the demo.

Greetz DraX    
Logged
I'm Lost!

raychaser

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 16
    • View Profile
Re: self defined global function
« Reply #4 on: June 17, 2007, 12:57:14 PM »

Hi Mnemonic,

I did exactly what you said above and I put the line

Code: [Select]
global Dlg = new Object("scripts\dialogs.script");
in my game.script file (but I also tried the game_daemon.script file)

the dialogs.script file contains the following:
Code: [Select]
method Dialogue1()
{
Game.Msg("booya");
}


now when I try to run the code "Dlg.Dialogue1();" from scenes\german\scr\window.script I get:  Error@line 12: Method is called for 'Dlg' which is not defined in the log file. I should mention that it works if I run "Dlg.Dialogue1();" from inside the game.script file.

Have I missed something? Why is my global variable not global?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: self defined global function
« Reply #5 on: June 17, 2007, 01:01:40 PM »

You need to declare the global variable in every script where it's going to be used. Just: global Dlg; will do. They variables will share the same global value, but they need to be declared so that the script "knows" about them.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.107 seconds with 23 queries.