Use item inventory on @HOTSPOT@

Started by , Thu 23/03/2006 23:30:48

Previous topic - Next topic

mudmarox

Hi everybody

I'm a newbye ..i'm web designer and cartoonist.
I began to build an adventure game since some weeks...i'm going not bad with that.
I'm going on with script thanks this forum..BUT...
Now i have a problem...i searched for this around  the wole forum, so please don't be angry with me if i ask this hint about script :)

I have a cursor menu and i wrote a code that show in the label "talk with @hotspot@" or "look at @hotspot@"

function repeatedly_execute() {


if (mouse.Mode ==0) lblStatus.SetText("go to @OVERHOTSPOT@");
if (mouse.Mode ==1) lblStatus.SetText("look at  @OVERHOTSPOT@");
if (mouse.Mode ==2) lblStatus.SetText("Interact with @OVERHOTSPOT@");
if (mouse.Mode ==3) lblStatus.SetText("Talk with @OVERHOTSPOT@");

Very simple and it works well with the 2.71

Now i need a command for the "USE WITH" cursor
Something like "Use (one of my items)  with @OVERHOTSPOT@" (where i guess %s is one of my inventory item).

I tried in everyway...but i still not found the solution...
Please help me...

P.S... Sorry for my English...i'm Italiano ^_^

Khris

Code: ags
if (mouse.Mode==eModeUseInv) {
Ã,  String buffer=player.ActiveInventory.Name;
Ã,  lblStatus.SetText("Use %s on @OVERHOTSPOT@", buffer);
}


This should work, too:

Code: ags
if (mouse.Mode==eModeUseInv) lblStatus.SetText("Use %s on @OVERHOTSPOT@", player.ActiveInventory.Name);

mudmarox

Hi KhrisMUC

Thanks for your help, but there is something that i don't understand, first of all...i don't know why ,AGS doesn't recognize "eModeUseInv" ...but i recovered with "4" the number wich refer the cursor for the inventory...then going on there is another herror...it says "

WRONG NUMBER OF PARAMETERS IN CALL TO LABEL ::SetText'

Why ???

Ashen

#3
AFAIK Label.SetText can't handle the extra parameters (%s, %d, etc) which KhrisMUC used. Try this instead:
Code: ags

if (mouse.Mode == 4) {
  String buffer=String.Format("Use %s on @OVERHOTSPOT@", player.ActiveInventory.Name);
  lblStatus.SetText(buffer);
}


Also, if you're using V2.71 (with the new String type) shouldn't you be using Label.Text, rather than SetText? (That can't handle the parameters either, so I think you'd have to use lblStatus.Text = buffer;)

About the eModeUseInv thing, try eModeUseinv (without the capitalised I) - unless you've renamed the modes. All the modes should have a eModeSomething version, to save you having to remember which number is which, and you should get an autocomplete list once you've typed eMode that you can pick the appropriate one from.
I know what you're thinking ... Don't think that.

mudmarox

Thankyou very much Ashen
Now it works perfectly !! :D

I hope to show  something concrete about my game soon..
Bye

MudMarox

RickJ

I believe that you could also just do this.   
Quote
if (mouse.Mode == 4) {
  lblStatus.Text = String.Format("Use %s on @OVERHOTSPOT@", player.ActiveInventory.Name);
}

Note: Also, I don't think it's a good practice to declare variables within conditional statements.  I like to do it at the beginning of the function declaration or at the top of the script.  Variables declared within a function are temporary and exist only as long as the function is executing.  Variables declared at the top of the script file remember their values permanently (even after game save/restore).


mudmarox

Hi RickJ

I guess you are right, the only problem for me is that i'm not a scripter ,i'm  a designer and cartoonist, but i'm trying to build up an adventure game either. The task is very hard, because i never scripted a thing. So I hope to receive help and suggestions by you guys sometimes.. written in style "script for dummies" =)))

Se you

MudMarox

Khris

Whoops, I didn't think :)

IMO, declaring the variable in the if-statement ist perfectly fine in this case, because it is used only once afterwards and won't be needed longer than 1/40 seconds.

RickJ

I'm sure there will be plenty of people willing to help you learn scripting.    The one advice I will give you at this point is to keep your script as organized and documented as possible.    To this end you should adopt some conventions for naming variables and functions and stick to it throughout your project.    There probably nearly as many programming conventions as there are programmers.   

For example I noticed that you are using the MS style of naming variables (hungarian notation?)  where an abbreviation of the data type is prepended to the descriptive part of the name.    I have a slightly different preference for naming Ags gui controls.   Ags automatically names each Gui by prepending a lower case 'g' to each Gui name.   Names given to controls are global in scope.  This means that these names must be unique and not defined anywhere else.  The way I choose to avoid having two things with the same name was to prepend the Gui's name to the control's name.   So, for example, instead of "lblStatus"  I may have used "gGuinameStatus".    Asking which one is best is a futile question, sort of like asking "Which is better a fork or spoon?".   Just pick the one you like.     

You may want to have a look at the current demo game and the programming conventions it uses.  They can be can be found here:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=23083.0

The reason I said that declaring variables within a conditional code block is not a very good practice is because doing this makes for difficult to read, difficult to debug, and error prone script.    Robust software is written to be changed and maintained over time.   Being unnecessarily clever is frowned upon, if you ever had to cleanup after a "clever programmer" you would know exactly what I mean.   Just because you can do something isn't necessarily a good reason to do it. 

I hope this is helpful to some folks.

mudmarox

That's fantastic !!

I took this demo and there is inside everything i need !!! EVERYTHING
With this ,my work should be easier now... :=
Thankyou very much RickJ, your hints are very helpfull for me.


SMF spam blocked by CleanTalk