SOLVED: set-globalint command does not work

Started by salak, Sat 27/07/2013 21:03:01

Previous topic - Next topic

salak

I wanted to make the value of a variable change after a dialog proceeds with the proper choices. Dialog goes like this:

.......
@3
cFake: Where are you, son?
cDopsu: I'm in the Dumbell Palace, dad.
cFake: What the hell are you doing there anyway? Just wait, I'm coming.
set-globalint 1 1
lose-inv 4
stop

The value is meant to change from 0 to 1 after this dialog, but I guess there must be something missing as the result of the change does not occur anyhow. AGS does not seem to show any error messages. Is it something about spelling or about the idea of using that command?

monkey0506

#1
I just tested this, and it works just fine. Why do you think that it's not being changed? Is it being changed somewhere else?

Code: ags
@3
cFake: Where are you, son?
cDopsu: I'm in the Dumbell Palace, dad.
cFake: What the hell are you doing there anyway? Just wait, I'm coming.
set-globalint 1 1
  if (GetGlobalInt(1) != 1) AbortGame("If the game aborts, it's not being set. If the game doesn't abort, then it is being set.");
lose-inv 4
stop


We need to see the other relevant code to determine why you think it's not being set.

By the way, you said that it should be getting set "after the dialog". Dialog.Start is a queued command, so if you're doing anything immediately after calling it, e.g.:

Code: ags
// some function
dDialog0.Start();
if (GetGlobalInt(1) != 1) Display("oh noes");


Then the if statement and display command here would be run before Dialog.Start. That's just how Dialog.Start works. But again, we need to see the code to see if that's what you're doing. If this is what you're doing, there's various ways to determine if a dialog is running and when it's stopped.

salak

thanks for reply.
well, actually function of a hotspot should have changed with the value. function is:

function hYukari_Interact()
{
if (deha_arandi == 0)
{player.ChangeRoom (8, 39, 173);}
else {
player.ChangeRoom (9, 39, 172);}
}

Function actually worked when I started the game with value=1. That's why I thought there's something wrong about the dialog, but I'm not sure about the function, either.

Khris

To be clear, set-globalint 1 1 / SetGlobalInt(1, 1); won't set the first global variable you have defined to 1, all it does is make GetGlobalInt(1) return 1.
You are checking for the value of deha_arandi, which was not affected in any way.

If you want to change that variable within a dialog, do so by using
Code: ags
 deha_arandi = 1;  // indent this line by one


As a side note: you don't need to put a single command within { and }. They are used to group things together, for instance when you want to run multiple commands conditionally.

salak

thanks a lot, this forum's a great help.

monkey0506

Quote from: Khris on Sun 28/07/2013 11:31:22To be clear, set-globalint 1 1 / SetGlobalInt(1, 1); won't set the first global variable you have defined to 1, all it does is make GetGlobalInt(1) return 1.
You are checking for the value of deha_arandi, which was not affected in any way.

Right. I hadn't even considered that salak may be using a named variable from the Global Variables pane.

SetGlobalInt/GetGlobalInt only refer to an internal set of unnamed integers (which is one of the reasons I recommend against using them). The Global Variables pane allows you to create your own named variables, and they can be used in all the same ways. It's just easier to keep track of who's doing what if they have a name instead of just an arbitrary ID (which is also why you should always give meaningful names to your Characters, Hotspots, Objects, GUIs, GUIControls, etc., etc.). ;)

salak

yes, the truth is I put my tail between my legs and learned to use run-script function, which I should have done in the beginning.

Khris

run-script? That and the accompanying dialog_request function are obsolete now, since you can put normal script commands right inside dialog scripts. All you need to do is indent the line by at least one space.

salak

I tried it but it caused en error. No wonder I made a mistake in dialog script. It's hard to be a total beginner with poor scripting skills :)

Khris

Just for reference, to use run-script, you'd do this in the dialog:
Code: ags
run-script 37   // no indentation, this line makes AGS call dialog_request(37);


Then add the dialog_request function to the global script:
Code: ags
function dialog_request(int param) {
  ...
  ...
  if (param == 37) {
    // stuff happens
  }
  ...
}


But, like I said, this is obsolete now, so don't use it!

SMF spam blocked by CleanTalk