Serious Sam's Bogus Detour

Serious Sam's Bogus Detour

Workshop
Create, share and play!
Learn More
kebabmaker 1 24 Jul, 2017 @ 6:02am
Help with custom script
trying to create a script which takes the value off a variable, and then displays it, but I am bad at angel script.

Errors = https://pasteboard.co/GCq5jCA.png
Code = https://pastebin.com/Xe6GvtCD

Line 35 Is where i am attempting to display it, setting the text of the scooby gui to the variable value
Last edited by kebabmaker; 24 Jul, 2017 @ 6:02am
< >
Showing 1-13 of 13 comments
Melissa  [developer] 2 24 Jul, 2017 @ 6:06am 
You forgot to close the body of ServerExecute (a missing } character)

You also have an extra } on line 50

You're also not returning anything in ServerExecute, make sure you add "return null;" at the end.

You probably also want to do: SetText("" + var.Value), since integers don't implicitly convert to strings.
Last edited by Melissa; 24 Jul, 2017 @ 6:09am
kebabmaker 1 24 Jul, 2017 @ 6:17am 
Hello, thankyou for your help.

https://pastebin.com/pTnM29g1

The editor does not report any compiling errors, however whenever I try to palce the script, I crash

I also apologise for my poor understanding.
Last edited by kebabmaker; 24 Jul, 2017 @ 6:19am
Melissa  [developer] 2 24 Jul, 2017 @ 6:24am 
Okay so in your constructor you have: ChangeScore(GUIBuilder@ b)

"b" here will always be null, because the engine does not construct a GUIBuilder for you. You will have to obtain the gamemode's GUIBuilder@ at runtime, eg. get it from a casted g_gameMode in the Initialize function of the script and then call LoadWidget.

I believe the editor crashes because of this because an exception in the constructor means the object will always be null, and the editor doesn't like that. I'll see if I can add an error for this instead of a crash.

Also, in your logfile, it shows this after the crash:
[ERR] [15:22:27] Script exception: [ERR] [15:22:27] Exception: Null pointer access [ERR] [15:22:27] Function: GUIDef@ IWidgetHoster::LoadWidget(GUIBuilder@, string) [ERR] [15:22:27] Line: 48 [ERR] [15:22:27] Call stack: [ERR] [15:22:27] [0] GUIDef@ IWidgetHoster::LoadWidget(GUIBuilder@, string) Line 48 [ERR] [15:22:27] [1] ChangeScore::ChangeScore(GUIBuilder@) Line 41 [ERR] [15:22:27] [2] WorldScript::ChangeScore@ ChangeScore(GUIBuilder@) Line 0
Last edited by Melissa; 24 Jul, 2017 @ 6:25am
kebabmaker 1 24 Jul, 2017 @ 6:33am 
I assume the casted gamemode at runtime is auto gamemode = cast<Survival>(g_gameMode);

So I need to initialize this?

https://pastebin.com/W4azsCwZ
Last edited by kebabmaker; 24 Jul, 2017 @ 6:34am
Melissa  [developer] 2 24 Jul, 2017 @ 6:50am 
Ah actually you don't need to cast it. Also, note that this code is inside of the Initialize() function, not the worldscript constructor.
void Initialize() { LoadWidget(g_gameMode.m_guiBuilder, "gui/hud/survival.gui"); @m_scoobyWidget = cast<TextWidget>(m_widget.GetWidgetById("scooby")); }
kebabmaker 1 24 Jul, 2017 @ 6:54am 
I am able to place it!! My script doesn't work however, but we got somewhere! Thanks a lot mate.
kebabmaker 1 24 Jul, 2017 @ 7:08am 
https://pastebin.com/KxhzWuTq = My GUI file

https://pastebin.com/GwjCBiK6 = The CheckScore Script


I cannot see why the script would not want to work however.

I tried using the SetText to say something, but that did not appear either, so It must be something within that
Last edited by kebabmaker; 24 Jul, 2017 @ 7:11am
Melissa  [developer] 2 24 Jul, 2017 @ 7:33am 
Have you read the Creating an Interface[ssbd.a000ff.com] article? You need to actually draw the interface as well, which means you'll also need to get a reference to your ChangeScore@ script (which is your widget hoster in your code!) and draw that.

Thinking about your code again, if you intend to have multiple ChangeScore worldscripts in your level, the behavior of your interface might not be what you expect, depending on how you handle the drawing of the widgets. (Since that would mean you have multiple widget hosters at the same time)
kebabmaker 1 25 Jul, 2017 @ 3:17am 
I was thinking about it, because I am using the survival GUI, is using the code on the wiki neccessary? As it seems you draw the GUI files as a whole, and I am using the survival GUI file, which should already be drawn somewhere else?

As well as that, when you want to draw the interface, where does the code actually go?a When you make an instance of the widget hoster and such, is this inside a new script, or one that already exsists (which I cannot locate)
kebabmaker 1 25 Jul, 2017 @ 3:59am 
So in the HUDSurvival, I added the scoobyWidget, and set the text of the scooby widget to:
m_scoobyWidget.SetText("♥♥♥♥);

This was under the update function.
Which worked correcty, as it was shown. So why does this not work on my ChangeScore script?
Last edited by kebabmaker; 25 Jul, 2017 @ 4:00am
Melissa  [developer] 2 25 Jul, 2017 @ 5:00am 
The examples on the wiki are drawing the widgets in a scripted gamemode. If you have a custom scripted gamemode, you can do it from there.

However, since you say you are already using HUDSurvival (which I assume you're doing in a custom scripted gamemode), you need to refer to that interface rather than make a completely new one with your worldscript.

For example, in the case that you are inheriting from (or directly using) the Survival gamemode, you could do something like this in a worldscript:
SValue@ ServerExecute() { // Get the Variable script UnitPtr unit = Variable.FetchFirst(); Variable@ var = cast<Variable>(unit.GetScriptBehavior()); // Get the gamemode and HUDSurvival object Survival@ gm = cast<Survival>(g_gameMode); HUDSurvival@ hudSurvival = gm.m_hudSurvival; // Get the score text widget auto wScore = cast<TextWidget>(hudSurvival.m_widget.GetWidgetById("score")); // Set the text wScore.SetText("" + var.Value); return null; }
(Note I did not test the above code snippet, but it should be fine)
Last edited by Melissa; 25 Jul, 2017 @ 5:01am
kebabmaker 1 25 Jul, 2017 @ 5:06am 
Sorry, I meant as the GUI file I am using, is survival.gui, which is where the things i want to change are held.
Last edited by kebabmaker; 25 Jul, 2017 @ 5:07am
Melissa  [developer] 2 25 Jul, 2017 @ 5:09am 
Right, also in that case my comment is still valid. What your ChangeScore script is doing, is setting a score on its own IWidgetHoster instead of the widget hoster that is actually being used to draw the survival HUD.
< >
Showing 1-13 of 13 comments
Per page: 1530 50